Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Opening a Word doc and more
Hi all,
I want to put a button in col A that will open a Word doc thats title is found in col B on the page number (of the doc) that is found in col C. Any ideas? Thanks all. Chris. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Opening a Word doc and more
Maybe more than you wanted but this should handle
everything you need. Dim wdAPP As Word.Application 'Bring in Word extensibility Dim wdDoc As Word.Document 'Identify a Word Document Dim sRNM As String 'Report Name 'Bring in Word Extensibility Set wdAPP = CreateObject("Word.Application") dAPP.Visible = True 'Open the Word Document sRNM = "C:\path\documentname.doc" Set wdAPP = CreateObject("Word.Application") Set wdDoc = wdAPP.Documents.Open(sRNM) WriteToWord("Text", linesbefore, linesafter, wdDOC, style) 'Save & Close the Word Document With wdDoc .Save .Close End With wdAPP.Visible = True wdAPP.Quit Set wdAPP = Nothing Set wdDoc = Nothing Sub PageBreak() wdAPP.Selection.EndKey Unit:=wdStory With wdDoc.Range .Characters.Last.InsertBreak Type:=wdPageBreak End With End Sub Sub SetTabs() wdAPP.Selection.ParagraphFormat.TabStops.Add _ Position:=InchesToPoints(0.25), _ Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces wdAPP.Selection.ParagraphFormat.TabStops.Add _ Position:=InchesToPoints(1.25), _ Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces wdAPP.Selection.ParagraphFormat.TabStops.Add _ Position:=InchesToPoints(4.5), _ Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces End Sub Public Function WriteToWord(sText As String, nBefore, nAfter As Integer, xDoc, Optional sStyle As String) Dim nCtr As Integer With xDoc If nBefore 0 Then For nCtr = 1 To nBefore .Content.InsertParagraphAfter Next nCtr End If If sStyle < "" Then wdAPP.Selection.EndKey Unit:=wdStory wdAPP.Selection.HomeKey Unit:=wdLine, Extend:=wdExtend wdAPP.Selection.Style = wdAPP.ActiveDocument.Styles(sStyle) End If .Content.InsertAfter sText For nCtr = 1 To nAfter .Content.InsertParagraphAfter Next nCtr End With End Function -----Original Message----- Hi all, I want to put a button in col A that will open a Word doc thats title is found in col B on the page number (of the doc) that is found in col C. Any ideas? Thanks all. Chris. . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
opening word document | Excel Discussion (Misc queries) | |||
Hyperlink to rtf only opening in MS Word | Excel Discussion (Misc queries) | |||
Opening a csv file in word | Excel Discussion (Misc queries) | |||
Opening spreadsheet & word very slow others ok | Excel Discussion (Misc queries) |