Results 1 to 31 of 31

Thread: MS Word Error(Resolved)

Threaded View

  1. #1

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    MS Word Error(Resolved)

    I'm taking an ascii data file and converting/moving the data into MS Word tables.
    It opens MS Word with the completed documemt.
    I've gotten that part working well.

    But here's the problem:
    It can not make more that one word doc unless you close/restart the program.

    If I try to make two documents in a row I get the following msg:
    Code:
    Runtime Error '462'
    The remote server machine does not exist or is unavailble.
    I get this error at line:
    Set myRange = ActiveDocument.Content

    I've only tried doing a second document after MS Word has been saved and closed.

    Full code:

    VB Code:
    1. Private Sub InsertToTemplate3(Columns() As String, ByRef Year As Integer)
    2. 'inserts the preformayed columns text into the template then saves it
    3.     Dim sPath As String
    4.     Dim MSWord As Word.Application
    5.     Dim TemplateDOC As Document
    6.     Dim myRange As Word.Range
    7.     Dim lM As Long
    8.     Dim lD As Long
    9.     Dim sFind As String
    10.    
    11.     staBar.Panels(1).Text = "Initalizing MSWord"
    12.     sPath = App.Path & "\Template\TableTemplate12g.dot"
    13.     Set MSWord = New Word.Application
    14.     With MSWord
    15. '        .Visible = True
    16.         'Load the template
    17.         Set TemplateDOC = .Documents.Open(sPath)
    18.         .Selection.WholeStory
    19.         .Selection.Copy
    20.         'create a ne document from the template
    21.         .Documents.Add DocumentType:=wdNewBlankDocument
    22.         .Selection.PasteAndFormat (wdPasteDefault)
    23.         Set myRange = ActiveDocument.Content
    24.         'notify the user
    25.         staBar.Panels(1).Text = "Creating Word Document"
    26.         Screen.MousePointer = vbDefault
    27.         ProgressBarInitalize 365
    28.        
    29.         'Set the Name of Location
    30.         sFind = "Name of Location"
    31.         myRange.Find.Execute FindText:=sFind, _
    32.                              MatchCase:=True, _
    33.                              MatchWholeWord:=True, _
    34.                              ReplaceWith:=m_sLocName, _
    35.                              Replace:=wdReplaceAll
    36.         'Set the Year
    37.         sFind = "Year"
    38.         myRange.Find.Execute FindText:=sFind, _
    39.                              MatchCase:=True, _
    40.                              MatchWholeWord:=True, _
    41.                              ReplaceWith:=CStr(Year), _
    42.                              Replace:=wdReplaceAll
    43.        
    44.         For lM = 1 To 12
    45.             For lD = 1 To 31
    46.                 ProgressBarDecrement
    47.                 'add the Day Numeral
    48.                 sFind = "Dm" & CStr(lM) & "d" & CStr(lD)
    49.                 myRange.Find.Execute FindText:=sFind, _
    50.                                      MatchCase:=True, _
    51.                                      MatchWholeWord:=True, _
    52.                                      ReplaceWith:=Columns(lM, 0, lD), _
    53.                                      Replace:=wdReplaceAll
    54.                 'add the Day Name
    55.                 sFind = "Wm" & CStr(lM) & "d" & CStr(lD)
    56.                 myRange.Find.Execute FindText:=sFind, _
    57.                                      MatchCase:=True, _
    58.                                      MatchWholeWord:=True, _
    59.                                      ReplaceWith:=Columns(lM, 1, lD), _
    60.                                      Replace:=wdReplaceAll
    61.                 'add the Moon Phase
    62.                 sFind = "Sm" & CStr(lM) & "d" & CStr(lD)
    63.                 myRange.Find.Execute FindText:=sFind, _
    64.                                      MatchCase:=True, _
    65.                                      MatchWholeWord:=True, _
    66.                                      ReplaceWith:=Columns(lM, 2, lD), _
    67.                                      Replace:=wdReplaceAll
    68.                
    69.                 'add the Time column
    70.                 sFind = "Tm" & CStr(lM) & "d" & CStr(lD)
    71.                 myRange.Find.Execute FindText:=sFind, _
    72.                                      MatchCase:=True, _
    73.                                      MatchWholeWord:=True, _
    74.                                      ReplaceWith:=Columns(lM, 3, lD), _
    75.                                      Replace:=wdReplaceAll
    76.             Next
    77.         Next
    78.         .Visible = True
    79.     End With
    80.     'Clear the progress bar
    81.     ProgressBarClear
    82.     staBar.Panels(1).Text = "Processing Complete"
    83.     staBar.Panels(2).Text = "Use MS Word to save the file."
    84.     'kill the MS Word objects
    85.     TemplateDOC.Close
    86.     Set MSWord = Nothing
    87.     Set TemplateDOC = Nothing
    88.     Set myRange = Nothing
    89. End Sub
    Last edited by longwolf; Jul 1st, 2005 at 06:48 PM. Reason: Resolved

Posting Permissions

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



Click Here to Expand Forum to Full Width