View Single Post
 
Old 02-16-2014, 02:56 PM
CIF CIF is offline Windows 7 32bit Office 2007
Novice
 
Join Date: Feb 2014
Posts: 7
CIF is on a distinguished road
Default

Thanks, Paul. I've highlighted the line where the error occurs. It only occurs sometimes though, so it seems to be some kind of timing thing.

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 
    myProject = ActiveWorkbook.Sheets("Project Setup").Range("B4") 
    myCompanyInfoL1 = ActiveWorkbook.Sheets("Project Setup").Range("B8") 
    myCompanyInfoL2 = ActiveWorkbook.Sheets("Project Setup").Range("B6") & " - " & ActiveWorkbook.Sheets("Project Setup").Range("B7") 
    myCompanyInfoL3 = ActiveWorkbook.Sheets("Project Setup").Range("B5") 
    myQuoteNumber = ActiveWorkbook.Sheets("Project Setup").Range("E4") 
    mycustomer = ActiveWorkbook.Sheets("Project Setup").Range("B6") 
    mydate = ActiveWorkbook.Sheets("Project Setup").Range("E5") 
    myuser = ActiveWorkbook.Sheets("Project Setup").Range("E7") 
    myDate1 = ActiveWorkbook.Sheets("Project Setup").Range("A45") 
    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\OpenCellQuote.dotx" 
        If .ActiveDocument.Bookmarks.Exists("Project") Then 
            .ActiveDocument.Bookmarks("Project").Range.Text = myProject 
        End If 
        If .ActiveDocument.Bookmarks.Exists("ToL1") Then 
            .ActiveDocument.Bookmarks("ToL1").Range.Text = myCompanyInfoL1 
        End If 
        If .ActiveDocument.Bookmarks.Exists("ToL2") Then 
            .ActiveDocument.Bookmarks("ToL2").Range.Text = myCompanyInfoL2 
        End If 
        If .ActiveDocument.Bookmarks.Exists("ToL3") Then 
            .ActiveDocument.Bookmarks("ToL3").Range.Text = myCompanyInfoL3 
        End If 
        If .ActiveDocument.Bookmarks.Exists("Date") Then 
            .ActiveDocument.Bookmarks("Date").Range.Text = mydate 
        End If 
        If .ActiveDocument.Bookmarks.Exists("User") Then 
            .ActiveDocument.Bookmarks("User").Range.Text = myuser 
        End If 
        If .ActiveDocument.Bookmarks.Exists("QuoteNo") Then 
            .ActiveDocument.Bookmarks("QuoteNo").Range.Text = myQuoteNumber 
        End If 
        If .ActiveDocument.Bookmarks.Exists("Esc") Then 
            .ActiveDocument.Bookmarks("Esc").Range.Text = myDate1 
        End If 
        If .ActiveDocument.Bookmarks.Exists("Table") Then 
            ThisWorkbook.Sheets("Quote OC Lay-in").Range("A11:H40").Copy 
            .Selection.GoTo What:=wdGoToBookmark, Name:="Table" 
            .Selection.Paste 
        End If 
        myFileName = myProject & " " & myQuoteNumber & "_" & mycustomer & " " & "Quote" & " " 
        With .Dialogs(wdDialogFileSummaryInfo) 
            .Title = myFileName 
            .Execute 
        End With 
        .Visible = True 
        .ActiveDocument.SaveAs ("G:\ABP\ArchSpec\Project Files\Quotes\2014\Premium\MW Open Cell\" & myFileName & Format(Date, "mm-dd-yy") & ".docx") 
    End With 
    Application.CutCopyMode = False 
    Application.ScreenUpdating = True 
End Sub

Last edited by macropod; 02-16-2014 at 03:01 PM. Reason: Added code tags & formatting
Reply With Quote