orangebloss
Board Regular
- Joined
- Jun 5, 2013
- Messages
- 51
- Office Version
- 365
- Platform
- Windows
I have 2 workbooks, DTR Index and DTR Template.
When the DTR index is completed I need to open the DTR template and paste the values from one range to another, then save as a new file name.
I was partially there but it doesn't seem to want to work - I get a Run time error 91: Object variable or with block variable not set
Any help much appreciated
When the DTR index is completed I need to open the DTR template and paste the values from one range to another, then save as a new file name.
I was partially there but it doesn't seem to want to work - I get a Run time error 91: Object variable or with block variable not set
Code:
Sub Sample()
Dim DTRINDEX As Workbook
Dim DTRTEMPLATE As Workbook
Dim path As String
Dim filename As String
path = "H:\Peter Test\"
filename = Range("F3")
Set DTRTEMPLATE = Workbooks.Open("T:\Server\Group\Two\PM\Peter\DTR_Template.xlsx")
'Copy the range to the new worksheet
DTRTEMPLATE.Sheets("DTR Form").Range("B2:F13").copy
'Paste special values to new worksheet
DTRINDEX.Sheets("DTR Form").Range("B2:F13").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
'Save the workbook with specified value as name
ActiveWorkbook.SaveAs filename:=path & filename & ".xlsx", FileFormat:=51
End Sub
Any help much appreciated