Importing sub documents with AddFromFile is creating multiple styles

  • Thread starter Doug Martin via OfficeKB.com
  • Start date
D

Doug Martin via OfficeKB.com

I use the macro below to import about 13 documents (full list not listed here to save space) into a Main document using Word 2000. All of the documents have been saved off of the Main document (using the main doc as a template) and they all run off the same .dot template for the styles.

Now, my problem is that it has been working fine up until I tweaked something or changed a setting somewhere (which I cannot think what) and now when I run the macro it brings all the documents in perfectly but multiplies most of the styles with the same name from the 13 documents ie:
New bullet
New bullet1
New bullet2
New bullet3 etc etc up to 13.
This problem also exists if I try and manually copy all the information from the sub documents into the main document (although it doesn?t seem as bad).

My question is, is there a line of code I can add or a setting which will rectify this problem? I have trawled through many forums regarding this but have yet to find a solution.

Any help will be much appreciated. Doug



Sub ImportSubDocuments()
On Error GoTo ImportSubDocuments_Err

Dim sFile As String
' ActiveDocument.Paragraphs.TabStops.ClearAll
ActiveWindow.ActivePane.View.Type = wdMasterView
Selection.Paragraphs.OutlinePromote

'stop the message box informing about styles being different
Application.DisplayAlerts = wdAlertsNone

sFile = "Introduction.doc"
ChangeFileOpenDirectory _
sMainDirectory & "Introduction\"
ActiveDocument.Subdocuments.AddFromFile Name:=sFile, _
ConfirmConversions:=False, ReadOnly:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:=""


sFile = "Consumer.doc"
ChangeFileOpenDirectory _
sMainDirectory & "Consumer\"
Selection.Range.Subdocuments.AddFromFile Name:=sFile, _
ConfirmConversions:=False, ReadOnly:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:=""

Exit Sub

ImportSubDocuments_Err:
If Err.Number = 5174 Then
MsgBox "Subdocument " & sFile & " can not be found, please check document name and location", vbExclamation, "Subdocument not found"
Else
MsgBox Err.Description & vbNewLine & Err.Number, vbExclamation, "Error loading subdocuments"
End If
End Sub
 
C

Cindy M -WordMVP-

Hi Doug,
Now, my problem is that it has been working fine up until I tweaked something or changed a setting somewhere (which I cannot think what) and now when I run the macro it brings all the documents in perfectly but multiplies most of the styles with the same name from the 13 documents ie:
New bullet
New bullet1
New bullet2
New bullet3 etc etc up to 13.
This problem also exists if I try and manually copy all the information from the sub documents into the main document (although it doesn?t seem as bad).
I think I've seen this, once or twice, but not in a LONG time...

The one thing that comes to mind would be the "smart style" setting in Tools/Options/Edit/Settings.

You might also try turning options off/on in Tools/AutoCorrect Options/AutoFormat

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply in the newsgroup and not by e-mail :)
 
D

Doug Martin via OfficeKB.com

Thanks for that Cindy, unfortunately that didnt work so I have to wait for
our IT department to reset my Word options/settings to see if that helps.
Will post if it turns out ok.
D
 
D

Doug Martin via OfficeKB.com

Well the problem is sorted but how I'm not too sure. Started Word using
the 'Run' dialogue box to load Word without macros and templates (ie a new
Normal.dot), that on its own didnt fix it. So, recreated my template (just
the page layout) and copied over the macros and styles from my original,
and voila all works.
Found out some pretty interesting stuff about Master documents too, nasty,
but unfortunately needed.
 
C

Cindy M -WordMVP-

Hi Doug,
Well the problem is sorted but how I'm not too sure... recreated my template (just
the page layout) and copied over the macros and styles from my original,
and voila all works.
In that case, I'm guessing some internal structures were damaged in the
template (stuff "stored in the last paragraph mark"). Thanks for reporting
back!

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top