Hi,
I am trying to run the code listed below and I get an run-time 91 error (Object variable or with block variable not set). Could someone please help me to understand why I am getting this error. Thanks.
Sub TestCode()
Dim mybook As Workbook, ElectricalCableSchedule As Workbook, mysheet As Worksheet, TCP As String, CableSchedule As Worksheet
Dim RngVisible As Range
Application.DisplayAlerts = False
Set mybook = Application.ActiveWorkbook
Set mysheet = Application.ActiveSheet
TCP = InputBox("Enter TCP")
Dim PIDsheet As Worksheet, rngTCP As Range, PIDFilename As String, Currentfilepath As String, Newfilepath As String
Set PIDsheet = mybook.Worksheets("TCP PIDs")
PIDsheet.Activate
Set rngTCP = PIDsheet.Range("$A$1:$A$100").Find(TCP)
rngTCP.Offset(0, 1).Select
PIDFilename = ActiveCell.Value
Currentfilepath = "\\nlnetappcifs01\n4wr\901_COMMISSIONING\901J_System_Turnover\TCP PIDs\All Scoped Drawings\New Scoped Drawings Unit 20 June 22" & PIDFilename
Newfilepath = ThisWorkbook.Path & "\PIDs" & PIDFilename
If Dir(Currentfilepath) <> "" Then
Else
If Dir(fullnewfilepath) <> "" Then
FileCopy Currentfilepath, Newfilepath
End If
End If
End Sub
I am trying to run the code listed below and I get an run-time 91 error (Object variable or with block variable not set). Could someone please help me to understand why I am getting this error. Thanks.
Sub TestCode()
Dim mybook As Workbook, ElectricalCableSchedule As Workbook, mysheet As Worksheet, TCP As String, CableSchedule As Worksheet
Dim RngVisible As Range
Application.DisplayAlerts = False
Set mybook = Application.ActiveWorkbook
Set mysheet = Application.ActiveSheet
TCP = InputBox("Enter TCP")
Dim PIDsheet As Worksheet, rngTCP As Range, PIDFilename As String, Currentfilepath As String, Newfilepath As String
Set PIDsheet = mybook.Worksheets("TCP PIDs")
PIDsheet.Activate
Set rngTCP = PIDsheet.Range("$A$1:$A$100").Find(TCP)
rngTCP.Offset(0, 1).Select
PIDFilename = ActiveCell.Value
Currentfilepath = "\\nlnetappcifs01\n4wr\901_COMMISSIONING\901J_System_Turnover\TCP PIDs\All Scoped Drawings\New Scoped Drawings Unit 20 June 22" & PIDFilename
Newfilepath = ThisWorkbook.Path & "\PIDs" & PIDFilename
If Dir(Currentfilepath) <> "" Then
Else
If Dir(fullnewfilepath) <> "" Then
FileCopy Currentfilepath, Newfilepath
End If
End If
End Sub