Macro: find/open/unprotect/unhide/copy/paste...

JoshuaGA

New Member
Joined
May 4, 2009
Messages
15
Hello, I need help with a Macro. I have found the individual elements but tying them all together where I'm unsure.

What I need to do is have a macro in (Workbook A) that will…

  1. open a workbook based on a file path in a specific cell (Workbook B)
  2. Unprotect Workbook B
  3. Unhide a specific sheet on Workbook B
  4. Copy the sheet and paste it into Workbook A
  5. Then protect Workbook B and close it.

I found this code that does a good job of opening the specified Workbook, it’s tying the other steps into this that I’m not sure about.

Sub Test()
Dim strFName As String

strFName = ThisWorkbook.Worksheets("Mapping").Range("P9").Value
'this variable contains the workbook name and path
If FileExists(strFName) Then
'does it exist?
If Not BookOpen(Dir(strFName)) Then Workbooks.Open Filename:=strFName
'if its not already open, open it
Else
MsgBox "The file does not exist!"
End If


End Sub

Function FileExists(strfullname As String) As Boolean
FileExists = Dir(strfullname) <> ""
End Function

Function BookOpen(strWBName As String) As Boolean
Dim wbk As Workbook
On Error Resume Next
Set wbk = Workbooks(strWBName)
If Not wbk Is Nothing Then BookOpen = True
End Function


Thanks.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,215,731
Messages
6,126,537
Members
449,316
Latest member
sravya

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