![]() |
#1
|
|||
|
|||
![]()
Hi there
I have a word doc of which I wanna run a macro automatically when it opens. I need it to open the document and then open "my documents " and then a folder within that. Can this be done. |
#2
|
||||
|
||||
![]()
Hi shreked,
You can do that by adding the following code to the document's 'This Document' module: Code:
Private Sub Document_Open() Dim StrFold As String With Application StrFold = .Options.DefaultFilePath(wdDocumentsPath) With .Dialogs(wdDialogFileOpen) .Name = "full path to folder, including final \" .Show End With .ChangeFileOpenDirectory StrFold End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
Thanks for that but where do I find "this document" module cos tried creating a macro for it and nothing happens.
|
#4
|
|||
|
|||
![]()
Apologies on that Ive found where I gotta find that.
Is there any way that I can get a message box come up saying "please choose template that applies" when it opens up the "open box" to click on what file to open. And being a pain can I close the original document when the 2nd doc opened. Thanks |
#5
|
||||
|
||||
![]()
Hi shreked,
Alt-F11, look for your document's name in the upper-left panel. Its 'This Document' module will already be there. Open that & paste the code.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#6
|
|||
|
|||
![]()
Thanks for that
|
#7
|
||||
|
||||
![]() Quote:
MsgBox "Please choose the template that applies" after: With Application Quote:
ThisDocument.Close SaveChanges:=False before: End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#8
|
|||
|
|||
![]()
Thats brill. One other little thing. How do I run a 2nd macro automatically once this ones run.
Private Sub Document_Open() Dim StrFold As String With Application MsgBox "Please choose the template that applies" StrFold = .Options.DefaultFilePath(wdDocumentsPath) With .Dialogs(wdDialogFileOpen) .Name = "\\cr-na2\users\glennm\test \" .Show End With .ChangeFileOpenDirectory StrFold End Sub |
#9
|
||||
|
||||
![]()
Hi shreked,
Unless that macro is a Document_Open macro or equivalent in the newly-opened document, you can't - it would have to be run before the document containing the above macro closes.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
icsjohn | Word VBA | 2 | 12-07-2011 06:44 PM |
![]() |
zsmithku | Word | 1 | 04-15-2011 03:46 PM |
Macro request: open on event | infotech | Outlook | 0 | 12-08-2010 06:40 PM |
Macro to open template not working | Brandi | Mail Merge | 2 | 06-24-2010 09:29 AM |
Word attachment on an E-mail-macro to open attachment & | nablady | Outlook | 0 | 11-28-2006 03:00 PM |