Thanks Thanks:  0
Likes Likes:  0
Results 1 to 10 of 10

Thread: Run Time Error 4248 when opening Word Doc from Excel

  1. #1
    New Member
    Join Date
    Nov 2011
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Run Time Error 4248 when opening Word Doc from Excel

    I haved a pricing worksheet that our workgroup uses. It opens a Word Document from and Excel Worksheet and merges info from Excel to Word. It worked fine while everyone was using Office 2007. The users that have Office 2010 installed on their computers are getting a Run Time Error 4248 when they attempt to create the Word document from the Word Template. Here is a piece of the VBA code in the Excel worksheet.

    Dim wrdApp As Word.Application
    Set wrdApp = CreateObject("Word.Application")
    Application.ScreenUpdating = False
    With wrdApp
    .Documents.Add Template:="G:\ABP\ArchSpec\A-Operations\Group Templates\Quote Templates\MWLinearQuote.dotx"

    Any help would be very much appreciated.

  2. #2
    Board Regular NdNoviceHlp's Avatar
    Join Date
    Nov 2002
    Location
    Manitoba Canada
    Posts
    1,990
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Run Time Error 4248 when opening Word Doc from Excel

    Check to make sure the 2010 edition has the Word reference selected in the VBA editor (Tools>references). HTH. Dave

  3. #3
    New Member
    Join Date
    Nov 2011
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Run Time Error 4248 when opening Word Doc from Excel

    Thanks, Dave. I did that and it is selected.

  4. #4
    Board Regular NdNoviceHlp's Avatar
    Join Date
    Nov 2002
    Location
    Manitoba Canada
    Posts
    1,990
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Run Time Error 4248 when opening Word Doc from Excel

    The only other thing I can suggest is to change the priority of the reference (ie. move it up the reference list). HTH. Dave

  5. #5
    New Member
    Join Date
    Nov 2011
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Run Time Error 4248 when opening Word Doc from Excel

    That didn't work either. I really appreciate the suggestions, though! This has caused a major disruption within my work group.

  6. #6
    Board Regular NdNoviceHlp's Avatar
    Join Date
    Nov 2002
    Location
    Manitoba Canada
    Posts
    1,990
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Run Time Error 4248 when opening Word Doc from Excel

    Are U sure the file extension is the same for both versions? Are U sure the file exists at the specified location? It would also be helpfull to know on what line the error occurs. Dave

  7. #7
    Board Regular Kenneth Hobson's Avatar
    Join Date
    Feb 2007
    Location
    Tecumseh, OK
    Posts
    2,804
    Post Thanks / Like
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Run Time Error 4248 when opening Word Doc from Excel

    You can use Dir() to see if a file exists:
    Code:
    Debug.Print Dir("G:\ABP\ArchSpec\A-Operations\Group Templates\Quote Templates\MWLinearQuote.dotx")<>""
    If an instance of MSWord already exists, you probably don't want to create another. See if this helps.
    Code:
    'http://vbaexpress.com/forum/showthread.php?p=185718
    Sub ExportFinalColumnToWord()
        Dim wdApp As Word.Application
        Dim myDoc As Word.Document
        Dim mywdRange As Word.Range
        Dim MyColumnA As Excel.Range
        Dim MyColumnB As Excel.Range
        Dim MyColumnC As Excel.Range
        Dim MyColumnD As Excel.Range
        Dim doc As String
        
        doc = "x:\msword\MyFile.doc"
        If Dir(doc) = "" Then
          MsgBox "Error, file does not exist." & vbLf & doc, vbCritical, "File is Missing"
          Exit Sub
        End If
         
        On Error Resume Next
        Set wdApp = GetObject(, "Word.Application")
        If Err.Number <> 0 Then
            Set wdApp = CreateObject("Word.Application")
        End If
        On Error GoTo errorHandler
         
        Set myDoc = wdApp.Documents.Add(Template:=doc)
        wdApp.Visible = True
         
        GoTo errorExit
        Set MyColumnA = Sheets("MySheet").Range("A1").End(xlDown).Select
        Set MyColumnB = Sheets("MySheet").Range("B1").End(xlDown).Select
        Set MyColumnC = Sheets("MySheet").Range("C1").End(xlDown).Select
        Set MyColumnD = Sheets("MySheet").Range("D1").End(xlDown).Select
         
        With myDoc.Bookmarks
            .Item("bmMyColumnA").Range.InsertAfter MyColumnA
            .Item("bmMyColumnB").Range.InsertAfter MyColumnB
            .Item("bmMyColumnC").Range.InsertAfter MyColumnC
            .Item("bmMyColumnD").Range.InsertAfter MyColumnD
        End With
         
        Set wdApp = Nothing
        Set myDoc = Nothing
        Set mywdRange = Nothing
        Exit Sub
         
    errorExit:
        On Error Resume Next
        Set wdApp = Nothing
        Set myDoc = Nothing
        Set mywdRange = Nothing
        Exit Sub
     
    errorHandler:
        MsgBox "Unexpected error: " & Err.Number & vbLf & Err.Description
        Resume errorExit
    End Sub
    
    'or.....
    
    Sub CopytoWord()
    'Requires Tools > References > Microsoft Word 11.0 Object Library
        Dim wdApp As Word.Application
        Dim wdDoc As Word.Document
        Dim doc As String
        
        doc = "x:\msword\MyFile.doc"
        If Dir(doc) = "" Then
          MsgBox "Error, file does not exist." & vbLf & doc, vbCritical, "File is Missing"
          Exit Sub
        End If
     
        On Error GoTo errorHandler
     
        Set wdApp = New Word.Application
     
        With wdApp
            'Add makes a copy like from a template even though it may be a DOC file.
            Set wdDoc = .Documents.Add(Template:=doc)
            'Set wdDoc = .Documents.Open(doc)
            .Visible = True
        End With
     
        With wdDoc.Bookmarks
            .Item("testbm").Range.InsertAfter Worksheets("Sheet1").Range("A1").Value
        End With
     
    errorExit:
        Set wdDoc = Nothing
        Set wdApp = Nothing
     
        Exit Sub
     
    errorHandler:
        MsgBox "Unexpected error: " & Err.Number & vbLf & Err.Description
        Resume errorExit
     
    End Sub

  8. #8
    New Member
    Join Date
    Nov 2011
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Run Time Error 4248 when opening Word Doc from Excel

    The file does exist. All users are accessing it from the same network location. It seems to be a timing issue. I did move the reference up on the priority list and when users are in the office, they can access. When they are using the worksheet from a remote location, they get the run time error.

  9. #9
    New Member
    Join Date
    Nov 2011
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Run Time Error 4248 when opening Word Doc from Excel

    Thank you for taking the time to send this code, Kenneth. I am going to try to figure it out and will get back to you.

  10. #10
    New Member
    Join Date
    Nov 2011
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Run Time Error 4248 when opening Word Doc from Excel

    Just an update. Nothing I have tried thus far has worked. When the users send me their worksheets, I can't generate the word document quote either. It has something to do with the reference in VBA being Microsoft Word 14.0 Object Library (for the users who have Office 2010). I created these documents with 2007 and I still have 2007.

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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