Is it possible? Fetch data from password form protected workbook.

PeaceCheese

New Member
Joined
Aug 28, 2021
Messages
3
Office Version
  1. 365
Platform
  1. 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.

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
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
What starts the login form? Probably workbookopen.

Try to disable events before opening the workbook 1.
VBA Code:
Application.enableevents =False
If this doesn't work you may try:
VBA Code:
Application.AutomationSecurity = msoAutomationSecurityForceDisable
This should disable all macros in newly opened files
 
Upvote 0
Solution
What starts the login form? Probably workbookopen.

Try to disable events before opening the workbook 1.
VBA Code:
Application.enableevents =False
If this doesn't work you may try:
VBA Code:
Application.AutomationSecurity = msoAutomationSecurityForceDisable
This should disable all macros in newly opened files

Brilliant! Fricken Amazing!

I put Application.enableevents =False right before my open statement and it fetched the info and I never got the sign in prompt for Workbook 1.

Didn't try the second suggestion - first is working so why would I? LOL

I can't thank you enough.
 
Upvote 0
Don't forget to reset it back to TRUE.
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,395
Members
449,081
Latest member
JAMES KECULAH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top