VBA in MS Word

lomax

Board Regular
Joined
Nov 9, 2011
Messages
67
Hi All,

Have a simple enough question.

I have created a default style setting for all my MS Word documents. I have recorded a simple macro to change the styles in an existing document into my default style. My question is how do I reference the currently opened document without needing its location path. i.e. change Destination Path from "Z:\Projects\Existing Document Path.docx" to Currently opened document.

Hope this makes sense.

Code:
Sub AA_Font()
'
' AA_Font Macro
'
'
    With ActiveDocument
        .UpdateStylesOnOpen = False
        .AttachedTemplate = "Normal"
        .XMLSchemaReferences.AutomaticValidation = True
        .XMLSchemaReferences.AllowSaveAsXMLWithoutValidation = False
    End With
   
 Application.OrganizerCopy Source:= _
        "C:\Users\UserName\AppData\Roaming\Microsoft\Templates\Normal.dotm", _
       
 Destination:= _
        "Z:\Projects\Existing Document Path.docx" _
        , Name:="Normal", Object:=wdOrganizerObjectStyles


    Application.OrganizerCopy Source:= _
        "C:\Users\UserName\AppData\Roaming\Microsoft\Templates\Normal.dotm", _
        Destination:= _
        "Z:\Projects\Existing Document Path.docx" _
        , Name:="AA Appendix", Object:=wdOrganizerObjectStyles

'Etc...

EndSub
 
Last edited:

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try ActiveDocument.FullName, like you would in Excel (ActiveWorkbook.FullName).
 
Upvote 0
Ok was simple enough. Just wasn't sure how I reference the currently opened Document. For anybody else who searches this - code below:

Code:
Sub AA_Font()
'
' AA_Font Macro
'
'
Dim Doc As Document
Set Doc = ActiveDocument

    With ActiveDocument
        .UpdateStylesOnOpen = False
        .AttachedTemplate = "Normal"
        .XMLSchemaReferences.AutomaticValidation = True
        .XMLSchemaReferences.AllowSaveAsXMLWithoutValidation = False
    End With
    
Application.OrganizerCopy Source:= _
        "C:\Users\UserName\AppData\Roaming\Microsoft\Templates\Normal.dotm", _
       
 Destination:=Doc _
        , Name:="Normal", Object:=wdOrganizerObjectStyles
    
Application.OrganizerCopy Source:= _
        "C:\Users\UserName\AppData\Roaming\Microsoft\Templates\Normal.dotm", _
       
 Destination:=Doc _
        , Name:="AA Appendix", Object:=wdOrganizerObjectStyles

'Etc...

EndSub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,921
Messages
6,122,280
Members
449,075
Latest member
staticfluids

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