Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 10th, 2012  |  syntax: None  |  size: 1.08 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Word cannot open this document template
  2. Dim wdApp As New Word.Application
  3.     Dim wdDoc As Word.Document
  4.     Dim sFile As String
  5.  
  6.     sFile = "C:document directorydocument.doc"
  7.  
  8.     Set wdDoc = wdApp.Documents.Open(sFile)
  9.  
  10.     If Not wdDoc Is Nothing Then
  11.         wdDoc.Close False
  12.         Set wdDoc = Nothing
  13.     End If
  14.     wdApp.Quit False
  15.     Set wdApp = Nothing
  16.        
  17. Dim wdApp As New Word.Application
  18.     Dim wdDoc As Word.Document
  19.     Dim sFile As String
  20.  
  21.     sFile = "C:document directorydocument.doc"
  22.  
  23.     wdApp.Visible = True
  24.     wdApp.DisplayAlerts = wdAlertsNone
  25.  
  26.     On Error GoTo DidNotOpen
  27.  
  28.     Set wdDoc = wdApp.Documents.Open(sFile)
  29.  
  30.     On Error GoTo 0
  31.  
  32.     wdApp.DisplayAlerts = wdAlertsAll
  33.  
  34.     If Not wdDoc Is Nothing Then
  35.         wdDoc.Close True 'save the template change
  36.         Set wdDoc = Nothing
  37.     End If
  38.  
  39.     GoTo Exit_Proc
  40.  
  41.  
  42. DidNotOpen:
  43.     Set wdDoc = wdApp.Documents.Open(sFile) 'try again to see if it works
  44.  
  45.     If Not wdDoc Is Nothing Then
  46.         wdDoc.AttachedTemplate = ""
  47.     End If
  48.  
  49.     Resume Next
  50.  
  51. Exit_Proc:
  52.     wdApp.Quit False
  53.     Set wdApp = Nothing
  54. End Sub