Code stopped working

Lelewiwi

Board Regular
Joined
Nov 8, 2023
Messages
50
Office Version
  1. 365
Platform
  1. Windows
Good morning helpful peeps! I have some code that has all of a sudden stopped working. It was working, but has since stopped. All it does now is lets me select the import workbook and then asks me if I want to save the current workbook. Nothing else happens. Both workbooks are password protected and need to unlock to allow the import, then lock again after. Help!

VBA Code:
Public Sub subImportData()

Dim AutoSv As Boolean
Dim fd As Office.FileDialog
Dim strFile As String
Dim WbThisWorkbook As Workbook
Dim WbImportFrom As Workbook

ActiveSheet.Unprotect Password:="232323"

ActiveWorkbook.Save

Application.ScreenUpdating = False

Set WbThisWorkbook = ThisWorkbook

Set fd = Application.FileDialog(msoFileDialogFilePicker)

With fd

.Filters.Clear
.Filters.Add "Excel Files", "*.xls?", 1
.Title = "Choose an Excel file"
.AllowMultiSelect = False

.InitialFileName = ActiveWorkbook.Path

If .Show = True Then

strFile = .SelectedItems(1)

End If

End With

If strFile = "" Then
Application.ScreenUpdating = True
Exit Sub
End If

Workbooks.Open strFile, ReadOnly:=True
Set WbImportFrom = ActiveWorkbook

WbThisWorkbook.Sheets("Sheet1").Range("R6").Value = WbImportFrom.Sheets("Sheet1").Range("C2").Value
WbThisWorkbook.Sheets("Sheet1").Range("F23").Value = WbImportFrom.Sheets("Sheet1").Range("C2").Value
WbThisWorkbook.Sheets("Sheet1").Range("F42").Value = WbImportFrom.Sheets("Sheet1").Range("C2").Value
WbThisWorkbook.Sheets("Sheet1").Range("F56").Value = WbImportFrom.Sheets("Sheet1").Range("C2").Value
WbThisWorkbook.Sheets("Sheet1").Range("F74").Value = WbImportFrom.Sheets("Sheet1").Range("C2").Value
WbThisWorkbook.Sheets("Sheet1").Range("H8").Value = WbImportFrom.Sheets("Sheet1").Range("C1").Value

WbThisWorkbook.Sheets("Sheet1").Range("F26").Value = WbImportFrom.Sheets("Hidden").Range("C7").Value
WbThisWorkbook.Sheets("Sheet1").Range("F27").Value = WbImportFrom.Sheets("Hidden").Range("C8").Value
WbThisWorkbook.Sheets("Sheet1").Range("F28").Value = WbImportFrom.Sheets("Hidden").Range("C9").Value
WbThisWorkbook.Sheets("Hidden").Range("A2").Value = WbImportFrom.Sheets("Hidden").Range("D23").Value

WbThisWorkbook.Sheets("Sheet1").Range("F45").Value = WbImportFrom.Sheets("Hidden").Range("C11").Value
WbThisWorkbook.Sheets("Sheet1").Range("F46").Value = WbImportFrom.Sheets("Hidden").Range("C12").Value
WbThisWorkbook.Sheets("Sheet1").Range("F47").Value = WbImportFrom.Sheets("Hidden").Range("C13").Value
WbThisWorkbook.Sheets("Hidden").Range("A5").Value = WbImportFrom.Sheets("Hidden").Range("D24").Value

WbThisWorkbook.Sheets("Sheet1").Range("F59").Value = WbImportFrom.Sheets("Hidden").Range("C15").Value
WbThisWorkbook.Sheets("Sheet1").Range("F60").Value = WbImportFrom.Sheets("Hidden").Range("C16").Value
WbThisWorkbook.Sheets("Sheet1").Range("F61").Value = WbImportFrom.Sheets("Hidden").Range("C17").Value
WbThisWorkbook.Sheets("Hidden").Range("A8").Value = WbImportFrom.Sheets("Hidden").Range("D25").Value

WbThisWorkbook.Sheets("Sheet1").Range("F77").Value = WbImportFrom.Sheets("Hidden").Range("C19").Value
WbThisWorkbook.Sheets("Sheet1").Range("F78").Value = WbImportFrom.Sheets("Hidden").Range("C20").Value
WbThisWorkbook.Sheets("Sheet1").Range("F79").Value = WbImportFrom.Sheets("Hidden").Range("C21").Value
WbThisWorkbook.Sheets("Hidden").Range("A11").Value = WbImportFrom.Sheets("Hidden").Range("D26").Value

WbThisWorkbook.Sheets("Hidden").Range("C15").Value = WbImportFrom.Sheets("Sheet1").Range("I24").Value
WbThisWorkbook.Sheets("Hidden").Range("C16").Value = WbImportFrom.Sheets("Sheet1").Range("I25").Value
WbThisWorkbook.Sheets("Hidden").Range("C17").Value = WbImportFrom.Sheets("Sheet1").Range("I26").Value
WbThisWorkbook.Sheets("Hidden").Range("C18").Value = WbImportFrom.Sheets("Sheet1").Range("I27").Value

WbImportFrom.Close

Application.ScreenUpdating = False

ActiveSheet.Protect Password:="232323"

End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
All I can suggest is that you step through the code (F8) and watch where it goes and see if your variables have the expected values because there's nothing obvious there. Some people will download a wb copy from a drive share if you want to go there.
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,954
Members
449,095
Latest member
nmaske

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