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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Import Word style Macro 1

Status
Not open for further replies.

nikka

Instructor
Mar 11, 2001
36
ZA
Hi how can I create a macro to import styles from one word document to another. However it must references the application and not the path name.

Thanks
Nikka
 
When you say application not path name I assume you mean the two files are open in Word. This macro uses the style organiser to copy the styles defined or modified in the active document to all other open documents:

Dim oStyle As Style
Dim oDocument As Document
For Each oDocument In Application.Documents
If oDocument.Name <> ActiveDocument.Name Then
For Each oStyle In ActiveDocument.Styles
If oStyle.InUse Then
Application.OrganizerCopy _
ActiveDocument.Name, _
oDocument.Name, _
oStyle.NameLocal, _
wdOrganizerObjectStyles
End If
Next oStyle
End If
Next oDocument

To write the macro select Tools->Macro->Macros, enter a name for the macro in the name box, select Normal.dot in the Macros In box and click Create. Copy the above code into the editor between SUB and END SUB. Close the editor. Run the macro by going back to Tools-Macro->Macros, select the macro and click Run.

Any good?
 
I get an error of file not found
The code breaks
at: Application.OrganizerCopy _
ActiveDocument.Name, _
oDocument.Name, _
oStyle.NameLocal, _
wdOrganizerObjectStyles

Thanks

Nikka
 
Insufficient testing! I got that right out of the on-line help file too!

Wherever the code refers to .Name change it to .FullName (don't touch the .NameLocal properties)

I've tested that with various saved files and it works on my system (before I just created two new files but didn't save them)

Sorry, now does it do what you want?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top