Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #8  
Old 02-16-2014, 04:45 PM
macropod's Avatar
macropod macropod is offline Run Time Error 4248 when opening Word Doc from Excel Windows 7 32bit Run Time Error 4248 when opening Word Doc from Excel Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,371
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Code:
Sub OCLayin_CreateQuote()
     'Collect the Needed Information
    Dim myProject, myCompanyInfoL1, myCompanyInfoL2, myCompanyInfoL3, myQuoteNumber As String
    Dim mycustomer, mydate As String, myuser As String, myDate1 As String, myDate2 As String, myDate3 As String
    Dim myFileName As String
    Dim wrdApp As Word.Application, wrdDoc As Word.Document
    Set wrdApp = CreateObject("Word.Application")
    Application.ScreenUpdating = False
    With ActiveWorkbook.Sheets("Project Setup")
        myProject = .Range("B4").Text
        myCompanyInfoL1 = .Range("B8").Text
        myCompanyInfoL2 = .Range("B6").Text & " - " & .Range("B7").Text
        myCompanyInfoL3 = .Range("B5").Text
        myQuoteNumber = .Range("E4").Text
        mycustomer = .Range("B6").Text
        mydate = .Range("E5").Text
        myuser = .Range("E7").Text
        myDate1 = .Range("A45").Text
    End With
    Set wrdDoc = wrdApp.Documents.Add(Template:= _
    "G:\ABP\ArchSpec\A-Operations\Group Templates\Quote Templates\OpenCellQuote.dotx")
    Do While wrdDoc Is Nothing: Loop
    With wrdDoc
        If .Bookmarks.Exists("Project") Then .Bookmarks("Project").Range.Text = myProject
        If .Bookmarks.Exists("ToL1") Then .Bookmarks("ToL1").Range.Text = myCompanyInfoL1
        If .Bookmarks.Exists("ToL2") Then .Bookmarks("ToL2").Range.Text = myCompanyInfoL2
        If .Bookmarks.Exists("ToL3") Then .Bookmarks("ToL3").Range.Text = myCompanyInfoL3
        If .Bookmarks.Exists("Date") Then .Bookmarks("Date").Range.Text = mydate
        If .Bookmarks.Exists("User") Then .Bookmarks("User").Range.Text = myuser
        If .Bookmarks.Exists("QuoteNo") Then .Bookmarks("QuoteNo").Range.Text = myQuoteNumber
        If .Bookmarks.Exists("Esc") Then .Bookmarks("Esc").Range.Text = myDate1
        If .Bookmarks.Exists("Table") Then
            ThisWorkbook.Sheets("Quote OC Lay-in").Range("A11:H40").Copy
            .Bookmarks("Table").Range.Paste
        End If
        myFileName = myProject & " " & myQuoteNumber & "_" & mycustomer & " " & "Quote" & " "
        With wrdApp.Dialogs(wdDialogFileSummaryInfo)
            .Title = myFileName
            .Execute
        End With
        .SaveAs2 "G:\ABP\ArchSpec\Project Files\Quotes\2014\Premium\MW Open Cell\" _
          & myFileName & Format(Date, "mm-dd-yy") & ".docx", _
          FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False
    End With
    wrdApp.Visible = True
    Set wrdDoc = Nothing: Set wrdApp = Nothing
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub
Note the revised code structure and the loop that forces Word to wait until the document being created is ready.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Run Time Error 4248 when opening Word Doc from Excel Run-time Error 5174: Open Word Documents from Excel tinfanide Excel Programming 3 10-01-2013 07:35 AM
Run Time Error 4248 when opening Word Doc from Excel Open Word w Excel & fill Word textboxes w info from Excel fields runtime error 4248 Joe Patrick Word VBA 2 01-30-2012 07:23 AM
Word Visual Basic error - run time error 504 crazymorton Word 11 01-13-2012 04:32 AM
Run Time Error 4248 when opening Word Doc from Excel MS Word - There was an error opening the file cookiegal Word 7 04-04-2011 12:37 AM
Error opening word from a doc. Davem501 Word 0 12-01-2009 02:10 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:57 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft