Failing To Reveal A Hidden Workbook From VBA From A Second Workbook

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,616
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Consider this code:
Rich (BB code):
Sub start_2()
    Dim mergeRange As Range
    Dim rng_src As Range, rng_dest As Range
    Dim wb_rmr As Workbook
    Dim ws_sand As Worksheet
    
    declaration
    'Stop
    With Workbooks("permit_info.xlsm").Worksheets("sheet1")
        .Range("I1, K1").Value = ""
    End With
    mbevents = False
    With ws_form
        If .ProtectContents = True Then .Unprotect
        .Range("I2") = ""
        If recall = 0 Then
            With .Range("E2")
                .Value = ""
                .Interior.Color = RGB(221, 235, 247)
                '.Borders.Color = RGB(48, 84, 150)
            End With
        End If
        'recall = 0
        With .Range("E3")
            .Value = ""
            .Interior.Color = RGB(189, 215, 238)
            '.Borders.Color = RGB(48, 84, 150)
            If .MergeCells = True Then
                Set mergeRange = .MergeArea
                mergeRange.Locked = True
            End If
        End With
        With .Range("W3, K15, V15")
            .Value = ""
            .Interior.Color = RGB(189, 215, 238)
            '.Borders.Color = RGB(48, 84, 150)
            If .MergeCells = True Then
                Set mergeRange = .MergeArea
                mergeRange.Locked = True
            End If
        End With
        With .Range("C6,F6,K6,R6,V6")
            .Value = ""
            .Interior.Color = RGB(189, 215, 238)
            '.Borders.Color = RGB(48, 84, 150)
        End With
        With .Range("C6")
            If .MergeCells = True Then
                Set mergeRange = .MergeArea
                mergeRange.Locked = True
            End If
        End With
        With .Range("F6")
            .Validation.Delete
            If .MergeCells = True Then
                Set mergeRange = .MergeArea
                mergeRange.Locked = True
            End If
        End With
        With .Range("K6")
            If .MergeCells = True Then
                Set mergeRange = .MergeArea
                mergeRange.Locked = True
            End If
        End With
        With .Range("R6")
            If .MergeCells = True Then
                Set mergeRange = .MergeArea
                mergeRange.Locked = True
            End If
        End With
        With .Range("V6")
            If .MergeCells = True Then
                Set mergeRange = .MergeArea
                mergeRange.Locked = True
            End If
        End With
        With .Range("K15")
            .Font.Color = vbBlack
            .Font.Bold = False
            If .MergeCells = True Then
                Set mergeRange = .MergeArea
                mergeRange.Locked = True
            End If
        End With
        With .Range("V15")
            .Font.Color = vbBlack
            .Font.Bold = False
            If .MergeCells = True Then
                Set mergeRange = .MergeArea
                mergeRange.Locked = True
            End If
        End With
        '.Range("E2").Select
        
        .Shapes("b_sh1u").Visible = False  'enable edit
        .Shapes("g_sh1u").Visible = True 'disable edit
        .Shapes("b_sh2u").Visible = False
        .Shapes("g_sh2u").Visible = True
        .Shapes("gn_sh2_submit").Visible = False
        .Shapes("g_sh2_submit").Visible = True
        
        If recall = 0 Then
            Set rng_src = wb_permit.Worksheets("Blocks").Range("A25:T29")
            Set rng_dest = ws_form.Range("G8")
            rng_src.Copy _
                Destination:=rng_dest
        Else
            Set rng_src = wb_permit.Worksheets("Blocks").Range("A25:T29")
            Set rng_dest = wb_permit.ws_form.Range("G8")
            rng_src.Copy _
                Destination:=rng_dest
            .Protect
            recall = 0
            .Protect
            Exit Sub
        End If
        .Protect
    End With
'Stop
    wb_permit.Windows(1).Visible = False
    mbevents = True
    If wb_permit.Worksheets("sheet1").Range("K1") = "dp" Then
        pn = wb_permit.Worksheets("sheet1").Range("I1")
        ws_form.Activate
        Call Worksheets("FORM").ReadingView
        MsgBox pn
        wb_permit.Windows(1).Visible = True
        ws_form.Range("E2").Select
    End If
End Sub

When this routine is launched, it basically resets the contents of a worksheet to it's default state in terms of values and formats and then hides it.
This worksheet and code resides in workbook 2 (wb_permit), the second of two open workbooks (wb_rmr).
It is user activity in workbook 1 (wb_rmr) that assigns the value of "dp" to range wb_permit.Worksheets("sheet1").Range("K1") and a value to wb_permit.Worksheets("sheet1").Range("I1") to refer to variablepn. . User initiated code in wb_rmr also launches this code. 
This code, when launched by the user from workbook 1 (wb_rmr) reaches the content in blue. A value of "dp" residing in range wb_permit.Worksheets("sheet1").Range("K1") triggers the remainder of the code.
The code in blue is intended to produce the following results ...
     - activate worksheet "form" in wb_permit (hidden)
     - call a procedure residing in wb_permit worksheets "FORM" which modifies the window - wb_permit worksheets("FORM") -  resizing it, removing static features like toolbars, tabs, ribbons, scrolllbars etc)
     - reveal (unhide) the modified worksheets("FORM") on top of wb_rmr behind it

I think I have the ordering of events wrong. When this code executes, the wb_permit.worksheet("FORM") window is not revealed.

Is anyone able to suggest a solution? If I have failed to provide adequate information, or the right information, to help support a solution, please ask for clarification. I'm unsure what information is relevant.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Have you tried?
I don't know the extension of you workbook. I assumed it is xlsx, but change as necessary
VBA Code:
Windows("wb_permit.xlsx").Visible = True
 
Upvote 0
Hi CountTepes, yes ... that recommendation worked. But, it has revealed that the
Code:
Application.Run "permit_info.xlsm!start_2"
isn't providing the expected results. The "start_2" routine is being accessed, but the call routine within (call ReadingView) it isn't performing. The permit_info.xlsm is supposed to open worksheet("FORM") on top of workbook 1 (wb_rmr) at a size defined in sub ReadingView, with ribbons, toolbars, tabs, formula bar, scrollbars etc. I am just getting a maximized normal window.
 
Upvote 0
Is start_2 routine, in a module or the workbook code area? If it is in a worksheet area, then you also need to specify the worksheet as well.
 
Upvote 0
Thanks for the quick reply!
Unfortunately, from the perspective of being an easy solution, the code is in a standard (?) module of it's own. Not in worksheet or workbook code.
 
Upvote 0
The ReadingView sub that is called from within the start_2 routine is in a worksheet module.
Here is a clip from the start_2 procedure that launches ReadingView.

Code:
Sub start_2
    ....
    If wb_permit.Worksheets("sheet1").Range("K1") = "dp" Then
        pn = wb_permit.Worksheets("sheet1").Range("I1")
        ws_form.Activate
        Call Worksheets("FORM").ReadingView
        MsgBox pn
        wb_permit.Windows(1).Visible = True
        ws_form.Range("E2").Select
    End If
    ....
End Sub
 
Last edited:
Upvote 0
Why are you hiding the workbook, which you are initialising?
 
Upvote 0
If you are referring to the full routine in post #1, it is a good question not knowing the scope of the whole project. I have since approached my logic differently hoping that will lead to some success. Until I have worked more on it, here is my my original logic for which the problem came to be:

Workbook permit_info.xlsm (wb2) is designed to be able to work independently, so it can be opened (put into a hidden state) via calling start_2 from the workbook open module . The start_2 procedure, through the 'If wb_permit.Worksheets("sheet1").Range("K1") = "dp" Then' condition failing prevents execution of the ReadingView routine, so the workbook, although hidden still remains in it's normal Excel state (no resized, tabs, ribbons etc still in place, just hidden) as there is no immediate need for those options on initial opening of wb2.

wb2 is tied into the main workbook (wb1) on two occassions.

First, wb1 opens wb2 so as to be able to access it's database which feeds data to the user interface of wb1. At that point, wb2 does not need to be visible. However, when wb1 opens wb2 initially, wb2's workbook open calls on routine start_2 to prepare worksheet("form") in anticipation to it's use later ... scenario 2 (excluding the resizing and other features tied to the ReadingView routine. So in this first circumstance, start_2 procedure simply opens hides the workbook, grabs data, and prepares the contents of worksheet("FORM") for future access. The if condition of the value in K1 is not met so that code is passed over.

Scenario two comes when the user, from wb1, wishes to access worksheet("FORM") in wb2. As you may suspect, worksheet ("Form") is a user accessible form of sorts (yes, I know vba has forms but my last crack at this project I used form extensively and things became overly complicated). This allows the user an interface to enter data to add to wb2's database. So, the idea now is to expose wb2 (unhide), assign a value of "dp" to worksheet1.range("K1"), so that when start_2 reaches that condition, it can launch the code to unhide the workbook, to worksheet("FORM") in a resized and "cleaned up" state as prepared by the ReadingView routine and cell values wiped during the initial opening of wb1. This allows the user to access worksheet("FORM") while still maintaining reference to wb1 behind it.

Worksheet("FORM") has links on it that allows the user to switch between (cleaned resized) ReadingView and Excel's default NormalView. These work well, but I am simply trying to automate the process of selecting the ReadingView link for the user. Perhaps I can just use vba to execute the link, but the issue is not being able to reveal the hidden workbook.

I will return with either success, or another question based on my restructuring.

I appreciate the patience and the support given thus far!
 
Upvote 0
If you do not require the WorkBook_Open event in wb2 to run, when it is opened by start_2, why not add Application.EnableEvents = False before you open it and then Application.EnableEvents = True afterwards.
 
Upvote 0
Hi again CountTepes ... I'm working through your suggestion to see where it all fits in. I'm not sure where in my start_2 I'm opening wb2.
This process is compounded in difficulty with my novice understanding of VBA. I'm sure what I am attempting to do in 200 lines of code can be done in 5. LOL
 
Upvote 0

Forum statistics

Threads
1,224,835
Messages
6,181,245
Members
453,026
Latest member
cknader

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