Run Time Error 4248 when opening Word Doc from Excel

CIF

New Member
Joined
Nov 1, 2011
Messages
6
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.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Check to make sure the 2010 edition has the Word reference selected in the VBA editor (Tools>references). HTH. Dave
 
Upvote 0
The only other thing I can suggest is to change the priority of the reference (ie. move it up the reference list). HTH. Dave
 
Upvote 0
That didn't work either. I really appreciate the suggestions, though! This has caused a major disruption within my work group.
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,213,497
Messages
6,113,998
Members
448,539
Latest member
alex78

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top