Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling Normal.dot macro closes current window

Status
Not open for further replies.

ohmbru

Technical User
Jul 13, 2001
161
US
I have posted this previously, but I don't think I explained the situation accurately. Let me try to do a better job:

In Word, I have an existing macro (Macro1)that is stored in Normal.dot. I'm running the following code from Excel which builds and executes a macro (Macro2) in a new Word document.

Sub Macro3()

Range("A1:K48").Select
Selection.Copy

Call CreateMacro2

End Sub


Sub CreateMacro2()
Dim app As Object
Dim doc As Object
Dim module As Object
Dim strCode As String

Set app = CreateObject("Word.Application")
app.Visible = True
Set doc = app.Documents.Add
Set module = doc.VBProject.VBComponents.Add(1)

strCode = "Sub Macro2()" & vbCr & _
"Selection.PasteSpecial Link:=False, DataType:=wdPasteMetafilePicture, _" & vbCr & _
"Placement:=wdFloatOverText, DisplayAsIcon:=False" & vbCr & _
"Application.Run MacroName:=""Macro1""" & vbCr & _
"End Sub"

module.CodeModule.AddFromString strCode
app.Run "Macro2"

End Sub

Macro2 that was built on the fly, looks like this:

Sub Macro2()
Selection.PasteSpecial Link:=False, DataType:=wdPasteMetafilePicture, _
Placement:=wdFloatOverText, DisplayAsIcon:=False
Application.Run MacroName:="Macro1"
End Sub

When the last line of Macro2 processes calling Macro1, my Word document unexpectedly closes. The Word document is critical to the process I'm trying to complete. I can't seem to get the original Word document to remain the active window when I call Macro1. When I step through the code, the window closes as soon as that line is executed (Application.Run MacroName:="Macro1").

I can manually call Macro1 without any problem.

I can't help thinking that it has something to do with Macro1 being stored in Normal.dot and Macro2 is in the current document.

I'm confused. Any help is appreciated.

Thanks,

Brian

Brian
 
Why don't you use

call macro1

instead of application.run "macro1"?
I'm not sure it would make a difference - but it might...


Rob
[flowerface]
 
Same result when I use Call Macro1 Brian
 
May your macro1 is corrupted. Try this out. search for support10.dot file in this url C:\Program Files\Microsoft Office\Office10\Macros. open this up they is an instruction how to autocorrect your macro
 
I was not able to find this file on the XP machine. I did find the Support8.dot but it doesn't have a an autocorrect feature.

Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top