<This question comes from a challenge I more or less created for myself in another thread>
In the Normal.dotm, I'd like to run code to load a template in the StartUp folder. Is there a universal location or variable I can use to make sure I can always find and load this file? In my case it's on OneDrive which makes the address pretty unique for my system.
Alternatively, things could also work if I could mimic a user typing Ctrl-N to create a new document. I tried to use SendKeys "^n" but somehow that doesn't seem to do anything...
Note: Ctrl-N is an alternative as that is already mapped to the special template in the StartUp folder. Simply doing a File.Open from VBA is not the solution.
Starting code from another template in Word or Sendkeys
-
- BronzeLounger
- Posts: 1258
- Joined: 03 Feb 2010, 19:59
- Location: Terneuzen, the Netherlands
-
- 4StarLounger
- Posts: 588
- Joined: 14 Nov 2012, 16:06
Re: Starting code from another template in Word or Sendkeys
Why not using an AddIn ?
-
- BronzeLounger
- Posts: 1258
- Joined: 03 Feb 2010, 19:59
- Location: Terneuzen, the Netherlands
Re: Starting code from another template in Word or Sendkeys
Sorry but I don't understand what you mean
-
- 4StarLounger
- Posts: 588
- Joined: 14 Nov 2012, 16:06
Re: Starting code from another template in Word or Sendkeys
Are you familiar with addIns ?
-
- BronzeLounger
- Posts: 1258
- Joined: 03 Feb 2010, 19:59
- Location: Terneuzen, the Netherlands
Re: Starting code from another template in Word or Sendkeys
Certainly... but I don't understand how an add-in can help me with my question
-
- 4StarLounger
- Posts: 564
- Joined: 27 Jun 2021, 10:46
Re: Starting code from another template in Word or Sendkeys
CTL-N is just Documents.Add DocumentType:=wdNewBlankDocument
-
- BronzeLounger
- Posts: 1258
- Joined: 03 Feb 2010, 19:59
- Location: Terneuzen, the Netherlands
Re: Starting code from another template in Word or Sendkeys
I know that, but as indicated in my question above: "Ctrl-N is <...> already mapped to the special template in the StartUp folder."
So in my case Ctrl-N does NOT open a blank document (and I don't want that), but a document based on a template where the proofing language is set to Dutch.
What I want is that if I open a new document via File-New, that new document is NOT a standard new document, but also the one based on the template mentioned above where the proofing language is Dutch. To do that, I need to interact in the "AutoNew" sub in Normal.dotm.
So in my case Ctrl-N does NOT open a blank document (and I don't want that), but a document based on a template where the proofing language is set to Dutch.
What I want is that if I open a new document via File-New, that new document is NOT a standard new document, but also the one based on the template mentioned above where the proofing language is Dutch. To do that, I need to interact in the "AutoNew" sub in Normal.dotm.
-
- 4StarLounger
- Posts: 588
- Joined: 14 Nov 2012, 16:06
Re: Starting code from another template in Word or Sendkeys
Please post a copy of your normal.dotm here.
Let's see whether we can adapt it to your wishes.
Let's see whether we can adapt it to your wishes.
-
- BronzeLounger
- Posts: 1258
- Joined: 03 Feb 2010, 19:59
- Location: Terneuzen, the Netherlands
Re: Starting code from another template in Word or Sendkeys
Again, if you read my original question you'll see that there's nothing relevant to post in my Normal.dotm...
I'm asking for this "In the Normal.dotm, I'd like to run code to load a template in the StartUp folder." and that should happen if I open a new Document, which means that code should go into the AutoNew of Normal.dotm.
I apologize as it seems that I'm again failing to explain what I'm looking for somehow. I re-read my original question and I think all is there. But below I've added some clarifications that may make it easier to follow I hope.
I'm asking for this "In the Normal.dotm, I'd like to run code to load a template in the StartUp folder." and that should happen if I open a new Document, which means that code should go into the AutoNew of Normal.dotm.
I apologize as it seems that I'm again failing to explain what I'm looking for somehow. I re-read my original question and I think all is there. But below I've added some clarifications that may make it easier to follow I hope.
In the Normal.dotm, I'd like to run code to load a template that is in the StartUp folder when I open a new file (therefore the code should be in the AutoNew sub in Normal.dotm).
Is there a universal location or variable defining the path to that Startup folder that I can use to make sure I can always find and load this template-file in the Startup folder?
In my case that folder is on OneDrive which makes the path pretty unique for my system.
Alternatively, things could also work if I could mimic a user typing Ctrl-N to create a new document from within the AutoNew sub in my Normal.dotm.
I tried to use SendKeys "^n" but somehow that doesn't seem to do anything...
Note: Ctrl-N is an alternative here as that key-press is already mapped to launch the special template in the StartUp folder. Simply doing a File.Open from VBA is not the solution as that won't launch the special template.
-
- 4StarLounger
- Posts: 588
- Joined: 14 Nov 2012, 16:06
Re: Starting code from another template in Word or Sendkeys
You can access any macromodule in Normaltemplate via the VBEditor.
-
- BronzeLounger
- Posts: 1258
- Joined: 03 Feb 2010, 19:59
- Location: Terneuzen, the Netherlands
Re: Starting code from another template in Word or Sendkeys
I know. The path is "C:\Users\<Windows User Name>\AppData\Roaming\Microsoft\Word\STARTUP". I can get the current Windows user and build that path probably (I thought I had seen a OneDrive URL earlier). Is that the most simple way then? And will it always point to the Word startup folder for all versions and installations of Word (that was the primary reason for my post)
-
- 4StarLounger
- Posts: 564
- Joined: 27 Jun 2021, 10:46
Re: Starting code from another template in Word or Sendkeys
Application.StartupPath
-
- BronzeLounger
- Posts: 1258
- Joined: 03 Feb 2010, 19:59
- Location: Terneuzen, the Netherlands
Re: Starting code from another template in Word or Sendkeys
Thanks, that was what I was looking for