Pretty new to vba, but I wrote a code that unmerges rows within a column, copies thus cells then pastes within a different macro workbook. The code ran well when I first ran it. However I attempted to use it today and I was shocked I had an error. This error stated that it could not find the destination file name. which was weird because the destination file name did not change or move. here is a sample of the code.
The error shows at line:
Set book2 = Workbooks.Open("Fiscal '17 Reported Straddle Fuel Usage.xlsm")
The code is as below:
Public Sub Button6_Click()
'Change name of button
Worksheets("7500").Buttons("Button 6").Text = "Send"
With Sheets("7500")
'Unmerge cells
.Range("AI3:AI92").Select
With Selection
For Each rCell In Selection
With rCell
If .MergeCells Then
.MergeArea.UnMerge
End If
End With
Next rCell
End With
End With
'open destination workbook
Dim book1 As Workbook
Dim sheet1 As Worksheet
Dim book2 As Workbook
Dim sheet2 As Worksheet
Application.ScreenUpdating = False
Set book1 = ThisWorkbook
Set book2 = Workbooks.Open("Fiscal '17 Reported Straddle Fuel Usage.xlsm")
Set sheet1 = book1.Sheets("7500")
Set sheet2 = book2.Sheets("Nov ‘17")