srikanth_s
New Member
- Joined
- Sep 1, 2009
- Messages
- 9
Hi All,
I'm very new to writing code and do a lot of copy/paste from the recorder. With that out of the way, I've written what seems like a fairly simple routine for creating a word doc out of content in an excel file. Both versions 2007. When my boss runs this in Excel/Word 2003 he gets the error cited in the subject line above 'Compile Error. Cannot find Project or Library.' I assume this is because I wrote it in 2007, and I assume I need to write it in a backwards-compatible way. My problem is I just don't know how to get started with figuring out which methods/arguments that I'm using are unavailable in 2003. My code is below; I'd love some guidance not only on what is awry with this code in particular, but more generally how to approach writing backwards-compatible code.
Thanks in advance
I'm very new to writing code and do a lot of copy/paste from the recorder. With that out of the way, I've written what seems like a fairly simple routine for creating a word doc out of content in an excel file. Both versions 2007. When my boss runs this in Excel/Word 2003 he gets the error cited in the subject line above 'Compile Error. Cannot find Project or Library.' I assume this is because I wrote it in 2007, and I assume I need to write it in a backwards-compatible way. My problem is I just don't know how to get started with figuring out which methods/arguments that I'm using are unavailable in 2003. My code is below; I'd love some guidance not only on what is awry with this code in particular, but more generally how to approach writing backwards-compatible code.
Code:
Private Sub cmdSendToWord_Click()
Dim i
Dim msWord As New Word.Application
msWord.Visible = True
msWord.Documents.Add
With msWord
.Selection.TypeParagraph
.Selection.InsertDateTime DateTimeFormat:="M/d/yyyy", InsertAsField:=False, _
DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern, _
InsertAsFullWidth:=False
.Selection.TypeParagraph
.Selection.TypeParagraph
.Selection.TypeText Text:="Dear "
.Selection.FormFields.Add Range:=.Selection.Range, Type:=wdFieldFormTextInput
.Selection.TypeText Text:=":"
.Selection.TypeParagraph
.Selection.Font.Size = 1
.Selection.TypeParagraph
.Selection.Font.Size = 11
.ActiveDocument.FormFields("Text1").Result = "RECIPIENT"
.Selection.FormFields.Add Range:=.Selection.Range, Type:=wdFieldFormTextInput
.ActiveDocument.FormFields("Text2").Result = "INTRODUCTORY TEXT"
End With
i = 4
Do
If Range("B" & i).Text = "" Then
Exit Do
End If
If Range("e" & i).Text = True Then
Range("B" & i, "D" & i).Copy
' msWord.Selection.PasteSpecial Link:=False, DataType:=wdPasteText, Placement:=wdInLine, DisplayAsIcon:=False
msWord.Selection.PasteExcelTable False, True, False
' msWord.Selection.TypeParagraph
msWord.ActiveDocument.PrintPreview
End If
i = i + 1
Loop
msWord.Selection.TypeParagraph
msWord.Selection.FormFields.Add Range:=msWord.Selection.Range, Type:=wdFieldFormTextInput
msWord.ActiveDocument.FormFields("Text3").Result = "CONCLUDING TEXT"
Application.CutCopyMode = False
ActiveSheet.Shapes("Picture 125").Copy
msWord.ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = True
msWord.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
msWord.ActiveWindow.Selection.Paste
msWord.ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
msWord.ActiveDocument.FormFields.Shaded = Not msWord.ActiveDocument.FormFields.Shaded
msWord.ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End Sub
Thanks in advance