Hi, I have never done coding. Someone told me how to write this. After finishing it I found I need something to copy value and not the formula. I found a DIM(the last one in the code) that might work but don't know how to finish it to read everything. Can someone tell me what exactly I need to write? Sorry its messy I have been adding notes...
Sub FillProposal()
'Define variables
Dim pricingSheet As Workbook
Dim macroWorkbook As Workbook
Dim wdapp As Word.Application
Dim proposalTemplate As Word.Document
Dim listLength As Integer
Dim strText As String
strText = Range("A1").Text
Dim dblNum As Double
dblNum = Range("A1").Value2
'Identify workbooks and open templates
Set pricingSheet = ActiveWorkbook
Windows("macro.xlsm").Activate
Set macroWorkbook = ActiveWorkbook
Set wdapp = New Word.Application
'Change file path when template is moved or renamed
Set proposalTemplate = wdapp.Documents.Open("C:\Users\natpi\Documents\CODED PROPOSAL TEMPLATE1.docx")
'C:\Users\Fine Arts\Documents\PRECISION SAFE SIDEWALKS\PSS TEMPLATES\PROPOSAL TEMPLATE REV 4-9-19 with excel pts (1).docx")
wdapp.Visible = True
'Find and replace Summary table
listLength = Application.WorksheetFunction.CountA(macroWorkbook.Sheets(1).Columns(1))
For i = 3 To listLength
wdapp.Activate
With wdapp.Selection.Find
.Text = macroWorkbook.Sheets(1).Cells(i, 1)
.Replacement.Text = pricingSheet.Sheets(1).Cells(macroWorkbook.Sheets(1).Cells(i, 2), macroWorkbook.Sheets(1).Cells(i, 3))
.Execute Replace:=wdReplaceAll
End With
Next
'to copy a formula result as a value instead of the formula, instead of '.Paste', use '.PasteSpecial'
'ActiveSheet.Paste Destination:=Worksheets("Positions").Range("W2")
'with this line:
'Worksheets("Positions").Range("W2").PasteSpecial xlPasteValues
'Find and replace Green table
listLength = Application.WorksheetFunction.CountA(macroWorkbook.Sheets(1).Columns(4))
For i = 3 To listLength
wdapp.Activate
With wdapp.Selection.Find
.Text = macroWorkbook.Sheets(1).Cells(i, 4)
.Replacement.Text = pricingSheet.Sheets(2).Cells(macroWorkbook.Sheets(1).Cells(i, 5), macroWorkbook.Sheets(1).Cells(i, 6))
.Execute Replace:=wdReplaceAll
End With
Next
End Sub
Sub FillProposal()
'Define variables
Dim pricingSheet As Workbook
Dim macroWorkbook As Workbook
Dim wdapp As Word.Application
Dim proposalTemplate As Word.Document
Dim listLength As Integer
Dim strText As String
strText = Range("A1").Text
Dim dblNum As Double
dblNum = Range("A1").Value2
'Identify workbooks and open templates
Set pricingSheet = ActiveWorkbook
Windows("macro.xlsm").Activate
Set macroWorkbook = ActiveWorkbook
Set wdapp = New Word.Application
'Change file path when template is moved or renamed
Set proposalTemplate = wdapp.Documents.Open("C:\Users\natpi\Documents\CODED PROPOSAL TEMPLATE1.docx")
'C:\Users\Fine Arts\Documents\PRECISION SAFE SIDEWALKS\PSS TEMPLATES\PROPOSAL TEMPLATE REV 4-9-19 with excel pts (1).docx")
wdapp.Visible = True
'Find and replace Summary table
listLength = Application.WorksheetFunction.CountA(macroWorkbook.Sheets(1).Columns(1))
For i = 3 To listLength
wdapp.Activate
With wdapp.Selection.Find
.Text = macroWorkbook.Sheets(1).Cells(i, 1)
.Replacement.Text = pricingSheet.Sheets(1).Cells(macroWorkbook.Sheets(1).Cells(i, 2), macroWorkbook.Sheets(1).Cells(i, 3))
.Execute Replace:=wdReplaceAll
End With
Next
'to copy a formula result as a value instead of the formula, instead of '.Paste', use '.PasteSpecial'
'ActiveSheet.Paste Destination:=Worksheets("Positions").Range("W2")
'with this line:
'Worksheets("Positions").Range("W2").PasteSpecial xlPasteValues
'Find and replace Green table
listLength = Application.WorksheetFunction.CountA(macroWorkbook.Sheets(1).Columns(4))
For i = 3 To listLength
wdapp.Activate
With wdapp.Selection.Find
.Text = macroWorkbook.Sheets(1).Cells(i, 4)
.Replacement.Text = pricingSheet.Sheets(2).Cells(macroWorkbook.Sheets(1).Cells(i, 5), macroWorkbook.Sheets(1).Cells(i, 6))
.Execute Replace:=wdReplaceAll
End With
Next
End Sub