ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Opening a Word doc and more (https://www.excelbanter.com/excel-programming/288887-opening-word-doc-more.html)

Merv[_2_]

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.




Taras

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.



.



All times are GMT +1. The time now is 09:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com