Hi all,
I have a spreadsheet that auto-populates certain data into a word template using bookmarks.
The issue I have is the data selection always changes dependant on the row number, the range column will always be the same, however the row number will change.
Could someone please help me out with how to set a range to always be the same column, but the row number will change dependant on the cursor selection made by the user?
Currently my code is as follows, which works as I would like it to, however currently the ranges are fixed as I couldn't figure out how to set the ranges as I would like to;
Private Sub cmdExport2Word_Click()
On Error GoTo errorHandler
Dim wdApp As Word.Application
Dim myDoc As Word.Document
Dim mywdRange As Word.Range
Dim Name As Excel.Range
Dim Quote As Excel.Range
Dim PM As Excel.Range
Dim PDate As Excel.Range
Dim ProjectDetail As Excel.Range
Dim Cost As Excel.Range
Set wdApp = New Word.Application
With wdApp
.Visible = True
.WindowState = wdWindowStateMaximize
End With
Set myDoc = wdApp.Documents.Add(Template:="C:\Users\DellR\Documents\TEST.docx")
Set Name = Sheets("Sheet1").Range("B3")
Set Quote = Sheets("Sheet1").Range("A3")
Set PM = Sheets("Sheet1").Range("C3")
Set PDate = Sheets("Sheet1").Range("D3")
Set ProjectDetail = Sheets("Sheet1").Range("G3")
Set Cost = Sheets("Sheet1").Range("F3")
With myDoc.Bookmarks
.Item("Name").Range.InsertAfter Name
.Item("Quote").Range.InsertAfter Quote
.Item("PM").Range.InsertAfter PM
.Item("PDate").Range.InsertAfter PDate
.Item("ProjectDetail").Range.InsertAfter ProjectDetail
.Item("Cost").Range.InsertAfter Cost
End With
errorHandler:
Set wdApp = Nothing
Set myDoc = Nothing
Set mywdRange = Nothing
End Sub
All your help is very much appreciated, I have attached the file for your reference.
Many thanks all
Dell
Bookmarks