Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-11-2012, 02:33 PM
shreked shreked is offline can I run a macro when I open a specific doc. Windows Vista can I run a macro when I open a specific doc. Office 2007
Novice
can I run a macro when I open a specific doc.
 
Join Date: Jan 2012
Posts: 10
shreked is on a distinguished road
Default can I run a macro when I open a specific doc.

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.
Reply With Quote
  #2  
Old 01-11-2012, 08:02 PM
macropod's Avatar
macropod macropod is offline can I run a macro when I open a specific doc. Windows 7 64bit can I run a macro when I open a specific doc. Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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
Note that the code switches the folder opening path back to the default after the dialogue is closed.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 01-12-2012, 12:36 AM
shreked shreked is offline can I run a macro when I open a specific doc. Windows Vista can I run a macro when I open a specific doc. Office 2007
Novice
can I run a macro when I open a specific doc.
 
Join Date: Jan 2012
Posts: 10
shreked is on a distinguished road
Default Where do I find "this document"

Thanks for that but where do I find "this document" module cos tried creating a macro for it and nothing happens.
Reply With Quote
  #4  
Old 01-12-2012, 12:45 AM
shreked shreked is offline can I run a macro when I open a specific doc. Windows Vista can I run a macro when I open a specific doc. Office 2007
Novice
can I run a macro when I open a specific doc.
 
Join Date: Jan 2012
Posts: 10
shreked is on a distinguished road
Default

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
Reply With Quote
  #5  
Old 01-12-2012, 12:45 AM
macropod's Avatar
macropod macropod is offline can I run a macro when I open a specific doc. Windows 7 64bit can I run a macro when I open a specific doc. Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #6  
Old 01-12-2012, 01:02 AM
shreked shreked is offline can I run a macro when I open a specific doc. Windows Vista can I run a macro when I open a specific doc. Office 2007
Novice
can I run a macro when I open a specific doc.
 
Join Date: Jan 2012
Posts: 10
shreked is on a distinguished road
Default

Thanks for that
Reply With Quote
  #7  
Old 01-12-2012, 02:22 AM
macropod's Avatar
macropod macropod is offline can I run a macro when I open a specific doc. Windows 7 64bit can I run a macro when I open a specific doc. Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by shreked View Post
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.
Yes, but you're really not going about this the right way. Be that as it may, add:
MsgBox "Please choose the template that applies"
after:
With Application
Quote:
Originally Posted by shreked View Post
And being a pain can I close the original document when the 2nd doc opened.
Yes, add:
ThisDocument.Close SaveChanges:=False
before:
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 01-12-2012, 02:54 AM
shreked shreked is offline can I run a macro when I open a specific doc. Windows Vista can I run a macro when I open a specific doc. Office 2007
Novice
can I run a macro when I open a specific doc.
 
Join Date: Jan 2012
Posts: 10
shreked is on a distinguished road
Default

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
Reply With Quote
  #9  
Old 01-12-2012, 03:36 AM
macropod's Avatar
macropod macropod is offline can I run a macro when I open a specific doc. Windows 7 64bit can I run a macro when I open a specific doc. Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
can I run a macro when I open a specific doc. Macro for highlighting specific number of words icsjohn Word VBA 2 12-07-2011 06:44 PM
can I run a macro when I open a specific doc. Need help extracting specific text from one doument to another with macro/VBA. 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

Other Forums: Access Forums

All times are GMT -7. The time now is 04:31 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft