OK, I have a workbook that is able to import worksheets from other workbooks, however, I would like to hide the information that is being imported so that users can't just double click on the workbook and edit it. I am having trouble getting the main workbook to import the data worksheets when I set them to very hidden and password protect the VBA. Here is what I started with and it worked great to import visible, unprotected worksheets:
This is what I have done to modify it:
For some reason my modified code is looping a bunch of times and copying each worksheet 12 times, not just once. I would like this code to open a workbook (selected by a user in a form, which already works great), unhide all sheets, copy the sheets, then close the imported workbook without saving so that the sheets are still hidden if the user opens the imported workbook in excel later. Any insight would be greatly appreciated! Thanks!
Code:
Private Sub InstallProducts_Click()
Application.ScreenUpdating = False
If FilePath.Value = "" Then
MsgBox "Please Select a File to Install", vbOKOnly
Exit Sub
Else
Unload Me
unprotect
Dim wkbSource As Workbook
Dim wkbTarget As Workbook
Dim WorkbookName As String
WorkbookName = ThisWorkbook.Name
Set wkbTarget = Workbooks(WorkbookName)
Set wkbSource = Workbooks.Open(FilePath.Value)
wkbSource.Sheets.Copy After:=wkbTarget.Sheets(wkbTarget.Sheets.Count)
wkbSource.Activate
ActiveWorkbook.Close SaveChanges:=True
End If
Application.ScreenUpdating = True
End Sub
Code:
Private Sub InstallProducts_Click()
Application.ScreenUpdating = False
If FilePath.Value = "" Then
MsgBox "Please Select a File to Install", vbOKOnly
Exit Sub
Else
Unload Me
unprotect
Dim wkbSource As Workbook
Dim wkbTarget As Workbook
Dim WorkbookName As String
WorkbookName = ThisWorkbook.Name
Set wkbTarget = Workbooks(WorkbookName)
Set wkbSource = Workbooks.Open(FilePath.Value)
For Each sh In wkbSource.Worksheets
If sh.Name <> "Sheet1" Then
wkbSource.Sheets.Copy After:=wkbTarget.Sheets(wkbTarget.Sheets.Count)
End If
Next sh
wkbSource.Activate
ActiveWorkbook.Close SaveChanges:=False
End If
Application.ScreenUpdating = True
End Sub