Andy Becker
New Member
- Joined
- May 17, 2022
- Messages
- 2
- Office Version
- 365
- Platform
- Windows
Hello, VBA beginner here. I have just started to learn VBA.
I found the following piece of code posted at: Macro prompts User to choose source workbook from folder and paste to destination workbook template
I do not know how to properly call the source worksheet to copy all data and select the target worksheet to paste all data. I would appreciate your help!
I found the following piece of code posted at: Macro prompts User to choose source workbook from folder and paste to destination workbook template
VBA Code:
Sub copyFromPlanillaReservas()
Application.ScreenUpdating = False
Dim cTr As Integer, i As Integer
Dim FilterType As String, Cap_One As String, TargetFileName As String, SourceFileName As String
Dim wbTARGET As Workbook, wbSOURCE As Workbook
Dim ws_TARGET As Worksheet, ws_SOURCE As Worksheet
FilterType = "Excel Files (*.xls*),*.xls*"
Cap_One = "Select [ SOURCE ] FILE "
SourceFileName = Application.GetOpenFilename(FilterType, , Cap_One)
If SourceFileName = "False" Then
MsgBox "Kindly Locate the SOURCE File location " & _
vbNewLine & "NO FILE was SELECTED Exiting.....", vbCritical + vbOKOnly, ".."
Exit Sub
End If
Cap_One = "Select [ TARGET ] FILE "
TargetFileName = Application.GetOpenFilename(FilterType, , Cap_One)
If TargetFileName = "False" Then
MsgBox "Kindly Locate the TARGET File location " & _
vbNewLine & "NO FILE was SELECTED Exiting.....", vbCritical + vbOKOnly, ".."
Exit Sub
End If
Set wbSOURCE = Workbooks.Open(SourceFileName)
wbSOURCE.Worksheets(1).Activate
Set ws_SOURCE = wbSOURCE.Worksheets(1)
Set wbTARGET = Workbooks.Open(TargetFileName)
wbTARGET.Worksheets(1).Activate
Set ws_TARGET = wbTARGET.Worksheets(1)
Application.ScreenUpdating = True
End Sub
I do not know how to properly call the source worksheet to copy all data and select the target worksheet to paste all data. I would appreciate your help!