PeaceCheese
New Member
- Joined
- Aug 28, 2021
- Messages
- 3
- Office Version
- 365
- Platform
- Windows
I have an excel workbook which has a sign in form. The sign in form has fields for “Purpose of visit” (dropdown selection), “date“, “username” and “password”. (For reference, I will call this workbook 1) When you sign into this workbook it launches another form where the user does all of their work/data entry.
I would like to use VBA from a different workbook (workbook 2) to get data from sheets in workbook 1.
Is there a way to do that in the background with VBA?
The code I have right now causes the workbook 1 sign in form to launch. If I sign into it then the work form will launch. I have to close that form then the data gets transferred.
I want everything to take place in the background. Is that possible?
Thanks in advance for any help with this.
I would like to use VBA from a different workbook (workbook 2) to get data from sheets in workbook 1.
Is there a way to do that in the background with VBA?
The code I have right now causes the workbook 1 sign in form to launch. If I sign into it then the work form will launch. I have to close that form then the data gets transferred.
I want everything to take place in the background. Is that possible?
Thanks in advance for any help with this.
VBA Code:
Private Sub cmd_pull_prev_report_Click()
Application.ScreenUpdating = False
Sheets("CPs").Visible = xlSheetVisible
Sheets("CPs").Activate
Rows("2:" & Rows.Count).ClearContents
Dim filepath As String
Dim sourceWb As Workbook
Dim TargetWb As Workbook
Dim rng As Range
Dim getaddressforpreviousfile As Range
Set TargetWb = ActiveWorkbook
Set rng = Sheets("Fac").Columns("B:B")
Set getaddressforpreviousfile = rng.find(What:=Fac_Code_For_Report, LookIn:=xlFormulas, LookAt:=xlWhole, MatchCase:=False)
filepath = UserRootURL & getaddressforpreviousfile.Offset(0, 25).Value
Set sourceWb = Workbooks.Open(filepath)
sourceWb.Sheets("CPs").Range("A2:T20").Copy Destination:=TargetWb.Sheets("CPs").Range("A2:T20")
sourceWb.Close
Application.ScreenUpdating = True
End Sub