I have a spreadsheet with code that will take information from that spreadsheet, open Word, and put that info into the document. Works great. The thing is, when I launch this thing, another spreadsheet pops up before the document comes up. It does not appear to make any difference other than I know it’s making the thing slower and it’s annoying. I have stepped through the program using Shift F8, but the spreadsheet does not pop up while I do this. But run it normally & bam, there it is!
Here is my attempt at programming. Don’t laugh. Have a look. Thanks!!
Public Sub WriteQuote()
‘On Error GoTo WriteQuoteError
Dim strLetter As String
Dim strDate As String
Dim strSalutation As String
Dim strTemplateDir As String
Dim objWord As Word.Application
Dim objDocs As Word.Documents
Dim prps As Object
Dim dp As Object
‘Set the Document Properties of this quote calc
Set dp = ActiveWorkbook.BuiltinDocumentProperties
dp(“Title”) = ActiveSheet.Range(“B2”)
dp(“Subject”) = ActiveSheet.Range(“B5”)
dp(“Author”) = “Robbie Harrison”
dp(“Company”) = “CCI Flooring Systems”
dp(“Category”) = FormatNumber(ActiveSheet.Range(“C6″), 0, vbUseDefault, vbUseDefault, vbTrue) & ” sf”
dp(“Keywords”) = “$” & FormatNumber(ActiveSheet.Range(“F73”), 2, vbUseDefault, vbUseDefault, vbTrue)
‘Open Word invisibly
Set objWord = CreateObject(“Word.Application”)
strTemplateDir = “D:WINDOWSDesktopCCIWord Processor Files”
strLetter = strTemplateDir & “Quote Template.dot”
‘Open a new quote based on this template
Set objDocs = objWord.Documents
objDocs.Add strLetter
objWord.Visible = True
‘Write info from contact item to document custom doc properties
Set prps = objWord.ActiveDocument.CustomDocumentProperties
strDate = FormatDateTime(ActiveSheet.Range(“F2”), vbLongDate)
prps.Item(“TodayDate”).Value = strDate
prps.Item(“Name”).Value = ActiveSheet.Range(“B1”)
prps.Item(“Address”).Value = ActiveSheet.Range(“B3”)
prps.Item(“CompanyName”).Value = ActiveSheet.Range(“B2”)
prps.Item(“AreaName”).Value = ActiveSheet.Range(“B5”)
prps.Item(“QuoteNumber”).Value = ActiveSheet.Range(“F3”)
prps.Item(“AreaSize”).Value = FormatNumber(ActiveSheet.Range(“C6”), 0, vbUseDefault, vbUseDefault, vbTrue)
prps.Item(“Amount”).Value = FormatNumber(ActiveSheet.Range(“F73”), 2, vbUseDefault, vbUseDefault, vbTrue)
objWord.ActiveDocument.Fields.Update
objWord.Activate
‘Set the Document Properties of the quote
Set dp = objWord.ActiveDocument.BuiltinDocumentProperties
dp(“Title”) = ActiveSheet.Range(“B2”)
dp(“Subject”) = ActiveSheet.Range(“B5”)
dp(“Author”) = “Robbie Harrison”
dp(“Company”) = “CCI Flooring Systems”
dp(“Category”) = FormatNumber(ActiveSheet.Range(“C6″), 0, vbUseDefault, vbUseDefault, vbTrue) & ” sf”
dp(“Keywords”) = “$” & FormatNumber(ActiveSheet.Range(“F73”), 2, vbUseDefault, vbUseDefault, vbTrue)
WriteQuoteExit:
Exit Sub
WriteQuoteError:
If Err.Number = 91 Then
MsgBox “There is no Inspector object open; exiting”
Else
MsgBox “Error No: ” & Err.Number & “; Description: ” & Err.Description
End If
Resume WriteQuoteExit
End Sub