+ Reply to Thread
Results 1 to 3 of 3

Error with macro to open Word doc and copy fields

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-15-2011
    Location
    Whitby, Canada
    MS-Off Ver
    Excel 2010
    Posts
    121

    Error with macro to open Word doc and copy fields

    Hi all,

    I have a macro to go to a specific folder on my shared drive, open the Word documents (forms that are filled out by other users) in that folder (Unprocessed), pull the data from it and insert it into the appropriate field - then, close the Word document and move it to another folder on the shared drive (Processed). This was all working great yesterday, now I keep getting and error at the line:

    wdApp.Documents.Open (fsFile)

    Can anyone help? I have attached a copy of my spreadsheet w/ macro and the template for the Word form.

    TIA
    Attached Files Attached Files

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Error with macro to open Word doc and copy fields

    Sub snb()
     With CreateObject("scripting.filesystemobject")
      For Each fl In .GetFolder("Z:\FireSuppression\test\MSA Tracking\UnProcessed").Files
       If .getextensionname(fl) = "doc" Then
        With GetObject(fl)
         Workbooks("MSA SCBA Tracking.xls").Sheets(1).Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(, 7) = Array(.FormFields(1).Result, .FormFields(2).Result, .FormFields(3).Result, .FormFields(4).Result, .FormFields(5).Result, .FormFields(6).Result, .FormFields(7).Result)
         .Close 0
        End With
    
        Name fsFile As "Z:\FireSuppression\test\MSA Tracking\Processed\" & Dir(fl)
       End if
      Next
     End With
    End Sub
    Last edited by snb; 12-23-2011 at 01:11 PM.



  3. #3
    Forum Contributor
    Join Date
    07-15-2011
    Location
    Whitby, Canada
    MS-Off Ver
    Excel 2010
    Posts
    121

    Re: Error with macro to open Word doc and copy fields

    Thanks - it seems as though the Word document was actually set up using a temporary template that was no longer in the same place and the error was the result of not being able to locate the template (which I had no knowledge of...) Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1