Page 1 of 2 12 LastLast
Results 1 to 15 of 29
  1. #1
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    122
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi all,

    I have the following vba that I'd like to use in order to convert batches of documents:

    Code:
    Sub convertprecedents()
    
        Const strPath = "L:\PrecedentConversionProject"
        
        'Loop counter
        Dim i As Integer
        
        'Doc variable
        Dim doc As Document
        
        With Application.FileSearch
            .FileType = msoFileTypeWordDocuments
            .LookIn = strPath
            .Execute
            
            
            For i = 1 To .FoundFiles.Count
            
            Application.StatusBar = "Processing" & .FoundFiles(i)
            
            Set doc = Documents.Open( _
            FileName:=.FoundFiles(i))
            
            ActiveDocument.CopyStylesFromTemplate Template:="C:\Program Files\Microsoft Office\Templates\Forms\non-legal documentation.dot"
            ActiveDocument.AttachedTemplate = "C:\Program Files\Microsoft Office\Templates\Forms\non-legal documentation.dot"
        
            doc.Close SaveChanges:=True
            
            Next i
            
        End With
        
    End Sub
    It falls down in that doc.close SaveChanges:=True doesn't execute due, I suspect, to interwoven integration. Can anyone advise me as to how to get around this please?

    Thanks in advance,

    Violet

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts
    It is probably not the cause of your problem, but I think you should not be referencing ActiveDocument in the middle of the loop, I think that you mean "doc".

  3. #3
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    122
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks Stuart - changed that but still falls down at doc.close savechanges:=true...

  4. #4
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts
    Quote Originally Posted by violet View Post
    Thanks Stuart - changed that but still falls down at doc.close savechanges:=true...
    Still worth changing though.

    You could try putting DoEvents on a line by itself just before (and just after) you close the document, in case something is going on in the background. It is a good idea to do this in any event when running a loop that could be quite long.

    Edited to add...
    It would also be good practice to put
    Set Doc = Nothing
    at the end, before the End Sub

  5. #5
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts
    Quote Originally Posted by violet View Post
    It falls down in that doc.close SaveChanges:=True doesn't execute due, I suspect, to interwoven integration. Can anyone advise me as to how to get around this please?
    As you say, it's likely that the Interwoven integration hooks into Word's DocumentSave event, in order to run its own code, and this is conflicting with your code. Would it be feasible (depending on who you user is, I guess) to turn off the Interwoven integration (even if just unloading the add-in via the user interface), before doing batch conversions of documents? - You could then have your user restart Word after the batch conversion is finished, to relaunch the Interwoven integation.

    Gary

  6. #6
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts
    Quote Originally Posted by violet View Post
    It falls down in that doc.close SaveChanges:=True doesn't execute due, I suspect, to interwoven integration. Can anyone advise me as to how to get around this please?
    As you say, it's likely that the Interwoven integration hooks into Word's DocumentSave event, in order to run its own code, and this is conflicting with your code. Would it be feasible (depending on who you user is, I guess) to turn off the Interwoven integration (even if just unloading the add-in via the user interface), before doing batch conversions of documents? - You could then have your user restart Word after the batch conversion is finished, to relaunch the Interwoven integation.

    Gary

  7. #7
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts
    Quote Originally Posted by violet View Post
    It falls down in that doc.close SaveChanges:=True doesn't execute due, I suspect, to interwoven integration. Can anyone advise me as to how to get around this please?
    As you say, it's likely that the Interwoven integration hooks into Word's DocumentSave event, in order to run its own code, and this is conflicting with your code. Would it be feasible (depending on who you user is, I guess) to turn off the Interwoven integration (even if just unloading the add-in via the user interface), before doing batch conversions of documents? - You could then have your user restart Word after the batch conversion is finished, to relaunch the Interwoven integation.

    Gary

  8. #8
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts
    Quote Originally Posted by violet View Post
    It falls down in that doc.close SaveChanges:=True doesn't execute due, I suspect, to interwoven integration. Can anyone advise me as to how to get around this please?
    As you say, it's likely that the Interwoven integration hooks into Word's DocumentSave event, in order to run its own code, and this is conflicting with your code. Would it be feasible (depending on who you user is, I guess) to turn off the Interwoven integration (even if just unloading the add-in via the user interface), before doing batch conversions of documents? - You could then have your user restart Word after the batch conversion is finished, to relaunch the Interwoven integation.

    Gary

  9. #9
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts
    Quote Originally Posted by violet View Post
    It falls down in that doc.close SaveChanges:=True doesn't execute due, I suspect, to interwoven integration. Can anyone advise me as to how to get around this please?
    As you say, it's likely that the Interwoven integration hooks into Word's DocumentSave event, in order to run its own code, and this is conflicting with your code. Would it be feasible (depending on who you user is, I guess) to turn off the Interwoven integration (even if just unloading the add-in via the user interface), before doing batch conversions of documents? - You could then have your user restart Word after the batch conversion is finished, to relaunch the Interwoven integation.

    Gary

  10. #10
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts
    Quote Originally Posted by violet View Post
    It falls down in that doc.close SaveChanges:=True doesn't execute due, I suspect, to interwoven integration. Can anyone advise me as to how to get around this please?
    As you say, it's likely that the Interwoven integration hooks into Word's DocumentSave event, in order to run its own code, and this is conflicting with your code. Would it be feasible (depending on who you user is, I guess) to turn off the Interwoven integration (even if just unloading the add-in via the user interface), before doing batch conversions of documents? - You could then have your user restart Word after the batch conversion is finished, to relaunch the Interwoven integation.

    Gary

  11. #11
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts
    Quote Originally Posted by violet View Post
    It falls down in that doc.close SaveChanges:=True doesn't execute due, I suspect, to interwoven integration. Can anyone advise me as to how to get around this please?
    As you say, it's likely that the Interwoven integration hooks into Word's DocumentSave event, in order to run its own code, and this is conflicting with your code. Would it be feasible (depending on who you user is, I guess) to turn off the Interwoven integration (even if just unloading the add-in via the user interface), before doing batch conversions of documents? - You could then have your user restart Word after the batch conversion is finished, to relaunch the Interwoven integation.

    Gary

  12. #12
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts
    Quote Originally Posted by violet View Post
    It falls down in that doc.close SaveChanges:=True doesn't execute due, I suspect, to interwoven integration. Can anyone advise me as to how to get around this please?
    As you say, it's likely that the Interwoven integration hooks into Word's DocumentSave event, in order to run its own code, and this is conflicting with your code. Would it be feasible (depending on who you user is, I guess) to turn off the Interwoven integration (even if just unloading the add-in via the user interface), before doing batch conversions of documents? - You could then have your user restart Word after the batch conversion is finished, to relaunch the Interwoven integation.

    Gary

  13. #13
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Hi Violet,

    I'd suggest something along the lines of:
    Code:
    Dim StrTemplate as String 
    StrTemplate = "C:\Program Files\Microsoft Office\Templates\Forms\non-legal documentation.dot"
    
    ...
    
    For i = 1 To .FoundFiles.Count        
      Application.StatusBar = "Processing" & .FoundFiles(i)
      Set doc = Documents.Open(FileName:=.FoundFiles(i))
      With doc
        .CopyStylesFromTemplate Template:=StrTemplate
        .AttachedTemplate = StrTemplate    
        .Close SaveChanges:=True
      End With
    Next
    Set doc = Nothing
    Do note that Application.FileSearch doesn't work in Office 2007 (or, I suspect, Office 2010). So, if you're looking to use this sub with current versions of Office, you may need to change to the Dir function.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  14. #14
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Hi Violet,

    I'd suggest something along the lines of:
    Code:
    Dim StrTemplate as String 
    StrTemplate = "C:\Program Files\Microsoft Office\Templates\Forms\non-legal documentation.dot"
    
    ...
    
    For i = 1 To .FoundFiles.Count        
      Application.StatusBar = "Processing" & .FoundFiles(i)
      Set doc = Documents.Open(FileName:=.FoundFiles(i))
      With doc
        .CopyStylesFromTemplate Template:=StrTemplate
        .AttachedTemplate = StrTemplate    
        .Close SaveChanges:=True
      End With
    Next
    Set doc = Nothing
    Do note that Application.FileSearch doesn't work in Office 2007 (or, I suspect, Office 2010). So, if you're looking to use this sub with current versions of Office, you may need to change to the Dir function.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  15. #15
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Hi Violet,

    I'd suggest something along the lines of:
    Code:
    Dim StrTemplate as String 
    StrTemplate = "C:\Program Files\Microsoft Office\Templates\Forms\non-legal documentation.dot"
    
    ...
    
    For i = 1 To .FoundFiles.Count        
      Application.StatusBar = "Processing" & .FoundFiles(i)
      Set doc = Documents.Open(FileName:=.FoundFiles(i))
      With doc
        .CopyStylesFromTemplate Template:=StrTemplate
        .AttachedTemplate = StrTemplate    
        .Close SaveChanges:=True
      End With
    Next
    Set doc = Nothing
    Do note that Application.FileSearch doesn't work in Office 2007 (or, I suspect, Office 2010). So, if you're looking to use this sub with current versions of Office, you may need to change to the Dir function.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •