P
peach255
I have a macro that manipulates the cells from 2
workbooks. It prompts for 2nd file to be open, do some
calculations, and then copy and paste some cells from 2nd
opened workbook to the 1st workbook. This procedure worked
fine when I run it from the .xls file. However, when I
have it as a add-in, this part did not work at all. I
tried debugging it, but it did not seem to recognize the 2
workbook files. My code is as follow:
Filename = Application.GetOpenFilename(FileFilter:=Filt,
Title:=Title)
'Exit if the dialog box canceled, else open file in new
workbook
If Filename = False Then
MsgBox "No file selected."
Exit Sub
Else
Workbooks.Open (Filename)
End If
Set wbOne = ThisWorkbook
Set wbTwo = Workbooks.Open(Filename:=Filename)
With wbOne
.Worksheets(1).Range("X9").Value = "Sample"
.Worksheets(1).Range("Y9").Value = "Name"
End With
'Copy range L10:L89 to X10
With wbTwo
.Worksheets(1).Range("O10").Copy
Destination:=wbOne.Worksheets(1).Range("AA10")
.Worksheets(1).Range("O20").Copy
Destination:=wbOne.Worksheets(1).Range("AA20")
End With
Thank you!
workbooks. It prompts for 2nd file to be open, do some
calculations, and then copy and paste some cells from 2nd
opened workbook to the 1st workbook. This procedure worked
fine when I run it from the .xls file. However, when I
have it as a add-in, this part did not work at all. I
tried debugging it, but it did not seem to recognize the 2
workbook files. My code is as follow:
Filename = Application.GetOpenFilename(FileFilter:=Filt,
Title:=Title)
'Exit if the dialog box canceled, else open file in new
workbook
If Filename = False Then
MsgBox "No file selected."
Exit Sub
Else
Workbooks.Open (Filename)
End If
Set wbOne = ThisWorkbook
Set wbTwo = Workbooks.Open(Filename:=Filename)
With wbOne
.Worksheets(1).Range("X9").Value = "Sample"
.Worksheets(1).Range("Y9").Value = "Name"
End With
'Copy range L10:L89 to X10
With wbTwo
.Worksheets(1).Range("O10").Copy
Destination:=wbOne.Worksheets(1).Range("AA10")
.Worksheets(1).Range("O20").Copy
Destination:=wbOne.Worksheets(1).Range("AA20")
End With
Thank you!