I am trying to open two workbooks using VBA, then copy selected contents from one to second. I wrote this code and can get the first workbook to open, then nothing happens. I am wondering if I should just open the first workbook, copy the selected contents to the desktop, close the first file, open the second and then paste?? Its been a while since I did VBA coding and my skills are pretty rusty. Thanks for your help;
Sub EvalResults()
Dim fProfFileNameAndPath As Variant
Dim folderSource As Variant
Dim myFile As String
Dim myPath As String
Dim myExtension As String
Dim wbProf As Workbook
Dim wbDest As Workbook
Dim filepathProf As String
Dim filepathDest As String
Dim LastRow As Long
Dim FldrPicker As FileDialog
fProfFileNameAndPath = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls),*.xls", Title:="Select Analyte Profile File To Be Opened")
If fProfFileNameAndPath = False Then Exit Sub
Set wbProf = Workbooks.Open(fProfFileNameAndPath)
'Retrieve Target Folder Path from User
Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)
With FldrPicker
.Title = "Select the Gen5 Prorenin Results Folder"
.AllowMultiSelect = False
myPath = .SelectedItems(1) & ""
End With
'Targe File Extension (must include wildcard "*")
myExtension = "*.xls*"
'Target Path With Ending Extension
myFile = Dir(myPath & myExtension)
'filepathProf = Application.GetOpenFilename("Excel Files (*.xlsx), *.xlsx*, *.xls", , , False)
'Set wbProf = Workbooks.Open(filepathProf)
'filepathDest = Application.GetOpenFilename("EXCEL Files (*.xlsx), *.xlsx*, *.xls", , , False)
'Set wbDest = Workbooks.Open(filepathDest)
With wbProf
.Sheets("Sheet1").Range("A1:D15").Copy wbDest.Sheets("Sheet1").Range("M17:P31")
.Sheets("Sheet1").Range("B19:B93").Copy wbDest.Sheets("Sheet1").Range("I76:I150")
End With
wbProf.Close SaveChanges:=False
End Sub
Sub EvalResults()
Dim fProfFileNameAndPath As Variant
Dim folderSource As Variant
Dim myFile As String
Dim myPath As String
Dim myExtension As String
Dim wbProf As Workbook
Dim wbDest As Workbook
Dim filepathProf As String
Dim filepathDest As String
Dim LastRow As Long
Dim FldrPicker As FileDialog
fProfFileNameAndPath = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls),*.xls", Title:="Select Analyte Profile File To Be Opened")
If fProfFileNameAndPath = False Then Exit Sub
Set wbProf = Workbooks.Open(fProfFileNameAndPath)
'Retrieve Target Folder Path from User
Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)
With FldrPicker
.Title = "Select the Gen5 Prorenin Results Folder"
.AllowMultiSelect = False
myPath = .SelectedItems(1) & ""
End With
'Targe File Extension (must include wildcard "*")
myExtension = "*.xls*"
'Target Path With Ending Extension
myFile = Dir(myPath & myExtension)
'filepathProf = Application.GetOpenFilename("Excel Files (*.xlsx), *.xlsx*, *.xls", , , False)
'Set wbProf = Workbooks.Open(filepathProf)
'filepathDest = Application.GetOpenFilename("EXCEL Files (*.xlsx), *.xlsx*, *.xls", , , False)
'Set wbDest = Workbooks.Open(filepathDest)
With wbProf
.Sheets("Sheet1").Range("A1:D15").Copy wbDest.Sheets("Sheet1").Range("M17:P31")
.Sheets("Sheet1").Range("B19:B93").Copy wbDest.Sheets("Sheet1").Range("I76:I150")
End With
wbProf.Close SaveChanges:=False
End Sub