Starting code from another template in Word or Sendkeys

User avatar
ErikJan
BronzeLounger
Posts: 1258
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Starting code from another template in Word or Sendkeys

Post by ErikJan »

<This question comes from a challenge I more or less created for myself :rofl: 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.

snb
4StarLounger
Posts: 588
Joined: 14 Nov 2012, 16:06

Re: Starting code from another template in Word or Sendkeys

Post by snb »

Why not using an AddIn ?

User avatar
ErikJan
BronzeLounger
Posts: 1258
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Starting code from another template in Word or Sendkeys

Post by ErikJan »

Sorry but I don't understand what you mean

snb
4StarLounger
Posts: 588
Joined: 14 Nov 2012, 16:06

Re: Starting code from another template in Word or Sendkeys

Post by snb »

Are you familiar with addIns ?

User avatar
ErikJan
BronzeLounger
Posts: 1258
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Starting code from another template in Word or Sendkeys

Post by ErikJan »

Certainly... but I don't understand how an add-in can help me with my question

User avatar
SpeakEasy
4StarLounger
Posts: 564
Joined: 27 Jun 2021, 10:46

Re: Starting code from another template in Word or Sendkeys

Post by SpeakEasy »

CTL-N is just Documents.Add DocumentType:=wdNewBlankDocument

User avatar
ErikJan
BronzeLounger
Posts: 1258
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Starting code from another template in Word or Sendkeys

Post by ErikJan »

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.

snb
4StarLounger
Posts: 588
Joined: 14 Nov 2012, 16:06

Re: Starting code from another template in Word or Sendkeys

Post by snb »

Please post a copy of your normal.dotm here.
Let's see whether we can adapt it to your wishes.

User avatar
ErikJan
BronzeLounger
Posts: 1258
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Starting code from another template in Word or Sendkeys

Post by ErikJan »

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.
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.

snb
4StarLounger
Posts: 588
Joined: 14 Nov 2012, 16:06

Re: Starting code from another template in Word or Sendkeys

Post by snb »

You can access any macromodule in Normaltemplate via the VBEditor.

User avatar
ErikJan
BronzeLounger
Posts: 1258
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Starting code from another template in Word or Sendkeys

Post by ErikJan »

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)

User avatar
SpeakEasy
4StarLounger
Posts: 564
Joined: 27 Jun 2021, 10:46

Re: Starting code from another template in Word or Sendkeys

Post by SpeakEasy »

Application.StartupPath

User avatar
ErikJan
BronzeLounger
Posts: 1258
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Starting code from another template in Word or Sendkeys

Post by ErikJan »

Thanks, that was what I was looking for