Code:
'To make OWord.inc go to the 'Tools' menu and select 'PowerBASIC COM Browser'. 'When the COM Browser opens go to the 'File' menu in the COM Browser and 'choose 'Open Registered Library...' You need to have some version of Word 'installed on your machine to use this program. Look for something like... ' 'Microsoft Word 9.0 Object Library 8.1 ' 'If you have a different version of Word it may say Word 97 or Word 10.0 or 'something else. Whatever version you have after you select it the COM 'Browser will display the COM Interfaces and Methods available in that 'object in the two list boxes. Next, once again on the 'File' menu choose 'Select All Interfaces'. Then on the 'File' menu choose "Save Interface 'To File'. When the 'Save File' dialog box appears save the file as 'OWord.inc. You can save it either in the PB Includes folder or in the 'apps folder. That's all there is to it. Should compile and run with either 'Console Compiler or Windows Compiler #Compile Exe #Dim All #Include "OWord.inc" %FALSE = 0 %TRUE = 1 Function PBMain () As Long Local vVnt,vBool,vFileName,vFileFmt,vText,vAnchor,vAddress,vAlignment As Variant Local oWord As WordApplication, oWordDoc As WordDocument Local oWordParaFmt As WordParagraphFormat Local oPageSetup As WordPageSetup Local oWordSel As WordSelection Local oRange As WordRange Local oFont As WordFont Register i As Long Set oWord=WordApplication In "Word.Application" If IsFalse IsObject(oWord) Then Set oWord=New WordApplication In "Word.Application" End If Object Call oWord.Documents.Add To vVnt Set oWordDoc=vVnt Object Get oWord.Selection To vVnt Set oWordSel=vVnt 'Page Setup ''Should Be 89 characters accross at Font = 10 Object Get oWordDoc.PageSetup To vVnt Set oPageSetup = vVnt vVnt = 36 Object Let oPageSetup.LeftMargin = vVnt Object Let oPageSetup.RightMargin = vVnt vVnt = 36 Object Let oPageSetup.TopMargin = vVnt Object Let oPageSetup.BottomMargin = vVnt 'Add page numbering in header (right aligned) vVnt=%wdSeekCurrentPageHeader Object Let oWord.ActiveWindow.ActivePane.View.SeekView=vVnt vAlignment=%wdAlignPageNumberRight vBool=%TRUE Object Call oWordSel.HeaderFooter.PageNumbers.Add(PageNumberAlignment=vAlignment,FirstPage=vBool) 'Add footer with text and hyperlink vVnt=%wdSeekCurrentPageFooter 'set active window to page footer Object Let oWord.ActiveWindow.ActivePane.View.SeekView=vVnt Object Get oWordSel.ParagraphFormat To vVnt 'get a reference to WordParagraphFormat object Set oWordParaFmt=vVnt 'set reference to dimentioned object vVnt=%wdAlignParagraphCenter 'equate to be fed to Paragraph Format Object Object Let oWordParaFmt.Alignment=vVnt 'set alignment in object vText="This and other prospectuses may be found on the WEB @" Object Call oWordSel.TypeText(vText) Object Call oWordSel.TypeParagraph Object Get oWordSel.Range To vAnchor 'One of the parameters of Hyperlinks.Add() method vAddress="http://www.state.pa.us/dcnr/forestry/timbersales" 'is a Selection.Range object Object Call oWord.ActiveDocument.Hyperlinks.Add(Anchor=vAnchor,Address=vAddress) 'Set Font to Courier New and also set sizes vVnt=%wdSeekMainDocument Object Let oWord.ActiveWindow.ActivePane.View.SeekView=vVnt Object Get oWordSel.Font To vVnt Set oFont = vVnt Let vVnt = "Courier New" Object Let oFont.Name = vVnt Let vVnt=10.0 Object Let oFont.Size=vVnt Let vBool=1 Object Let oFont.Bold=vBool 'Set text alignment, i.e., centering and so forth. Object Get oWordSel.ParagraphFormat To vVnt Set oWordParaFmt=vVnt vVnt=%wdAlignParagraphCenter Object Let oWordParaFmt.Alignment=vVnt vText = "Commonwealth of Pennsylvania" Object Call oWordSel.TypeText(vText) Object Call oWordSel.TypeParagraph vText = "Department of Conservation and Natural Resources" Object Call oWordSel.TypeText(vText) Object Call oWordSel.TypeParagraph Let vVnt=12.0 Object Let oFont.Size=vVnt vText="Bureau of Forestry" Object Call oWordSel.TypeText(vText) Object Call oWordSel.TypeParagraph Object Call oWordSel.TypeParagraph Let vVnt=13.5 Object Let oFont.Size=vVnt vText="PROSPECTUS" Object Call oWordSel.TypeText(vText) Object Call oWordSel.TypeParagraph Object Call oWordSel.TypeParagraph Object Call oWordSel.TypeParagraph Object Call oWordSel.TypeParagraph 'Display bunch of text at different fonts vVnt=%wdAlignParagraphLeft Object Let oWordParaFmt.Alignment=vVnt For i=6 To 30 Let vVnt=CSng(i) Object Let oFont.Size=vVnt Let vText = "Text With Font Size = " & Str$(i) Object Call oWordSel.TypeText(vText) Object Call oWordSel.TypeParagraph Next i 'Save to file vFileName = CurDir$ & "\Junk.doc" Let vFileFmt=%wdFormatDocument Object Call oWordDoc.SaveAs(vFileName,vFileFmt) Let vBool=%TRUE Object Let oWord.Visible=vBool Set oPageSetup=Nothing Set oFont=Nothing Set oWordSel=Nothing Set oWordParaFmt=Nothing Set oWordDoc=Nothing Set oWord=Nothing PBMain=0 End Function
Comment