Excel macro can't open word doc's that have templates

Pinkrope11

New Member
Joined
Oct 10, 2009
Messages
24
Hey everyone,

I've got a rather larger macro that runs from Excel and pulls data in from word documents. This macro works great for regular word documents that don't call templates. However, when the macro tries to open up a word document that is referencing a template, from what seems to be an auto call macro within the document, i get a run-time error:


Run-time error '5180':

Word cannoot open this document template.
(C:\...\Asdft Template.dot)


I can open the word document by hand on the computer without a problem I just can't get the macro to do it.

The link of code throwing the error within vba is:

Code:
Set wdDoc = wdApp.Documents.Open(Filename:=filepath)
If anyone has any suggestions I would really appreciate it!


Thanks in advance!
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
try this code:

Sub Openfile()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
YesNo = MsgBox("Would you like to open the folder to see" _<o:p></o:p>
& vbCr & "which files are currently there?", vbYesNo + vbQuestion, "Open file?")<o:p></o:p>
Select Case YesNo<o:p></o:p>
Case vbYes<o:p></o:p>
myval = Shell("C:\WINDOWS\explorer.EXE /e, C:\file path here\", 1)<o:p></o:p>
Case vbNo<o:p></o:p>
End Select<o:p></o:p>
End Sub<o:p></o:p>


Lets see if this works for you!
 
Upvote 0
It's giving me a type mismatch error when I try to set the shell command to a variable and when i change the variable type the resulting word code wont run. The problem is that I need to be able to use the wdDoc variable to search through the word document later in the code.


Is there a way to simply prevent the AutoOpen macro from running or even being called using vba?
 
Upvote 0
yea and that's the problem because i don't want the code within the word doc's to run because there is an autoOpen macro that runs in the word doc that messes up the execution of the original macro that is trying to run.
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,557
Members
449,088
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top