Option buttons not clickable after running VBA export code

Excel_dan

New Member
Joined
Jan 18, 2017
Messages
14
I have a spreadsheet that has an option button group where you can select 2 options. When I open the file I can select either option and this works perfectly. After I run code to export out the sheets to pdf when I hover over the options buttons the cursor shows a black circle with a slash through it. Is there a piece of code that is causing this issue or does anyone know how to resolve?

The cursor looks as shown here:
cursor error.JPG



The code that I am running is the following:

VBA Code:
Sub PrintSheet1()
    Dim wsA As Worksheet
    Dim wsB As Worksheet
    Dim valueInKS1 As Integer
    Dim sName As String
    Dim FileSelected As String
    

    On Error Resume Next
    sName = Left(ActiveWorkbook.Name, InStr(1, ActiveWorkbook.Name, ".") - 1)

    ' Turn off screen updating and automatic calculations for efficiency
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual

    ' Set worksheets (adjust sheet names if needed)
    Set wsA = Worksheets("Bioretention")
    Set wsB = Worksheets("Storage-Discharge")

    ' Get value from cell KS1 on the active sheet (assuming Bioretention)
    valueInKS1 = wsA.Range("KS1").Value

    Select Case valueInKS1
        Case 1
            ' Print only worksheet A directly using Sheets collection
            FileSelected = Application.GetSaveAsFilename(InitialFileName:=sName, _
                                         FileFilter:="PDF Files (*.pdf), *.pdf", _
                                         Title:="Save PDF as")
            If Not FileSelected <> "False" Then
                Exit Sub
            End If
            Sheets(Array("Bioretention")).Select
            ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
            Filename:=FileSelected, _
            OpenAfterPublish:=True
        Case 2
            ' Print both worksheets A and B directly using Sheets collection
            wsB.Visible = True
            FileSelected = Application.GetSaveAsFilename(InitialFileName:=sName, _
                                         FileFilter:="PDF Files (*.pdf), *.pdf", _
                                         Title:="Save PDF as")
            If Not FileSelected <> "False" Then
                Exit Sub
            End If
            Sheets(Array("Bioretention", "Storage-Discharge")).Select
            ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
            Filename:=FileSelected, _
            OpenAfterPublish:=True
            wsB.Visible = False
        Case Else
            ' Handle other cases (optional)
            MsgBox "Invalid value. No sheets printed. Please select Preliminary or Final Design"
    End Select

    ' Turn screen updating and automatic calculations back on
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
    wsA.Visible = True
End Sub

Any help is appreciated. Thank you.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Upon further review I have found that the options buttons are not clickable after running the code in Case 2. If I open the file and run the Case 1 it will export the pdf and the options buttons still work fine. The difference between Case 1 and Case 2 is Case 1 only exports 1 sheet and Case 2 exports 2 sheets so maybe there is an issue with selecting 2 sheets? The Code in question:

VBA Code:
        Case 2
            ' Print both worksheets A and B directly
            wsB.Visible = True
            FileSelected = Application.GetSaveAsFilename(InitialFileName:=sName, _
                                         FileFilter:="PDF Files (*.pdf), *.pdf", _
                                         Title:="Save PDF as")
            If Not FileSelected <> "False" Then
                Exit Sub
            End If
            Sheets(Array("Bioretention", "Storage-Discharge")).Select
            ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
            Filename:=FileSelected, _
            OpenAfterPublish:=True
            wsB.Visible = False
 
Upvote 0
That's because your two sheets ("Bioretention" and "Storage-Discharge") remain grouped after the procedure ends. You'll need to ungroup them after they've been exported...

VBA Code:
            '
            '
            '
            Sheets(Array("Bioretention", "Storage-Discharge")).Select
            ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
                Filename:=FileSelected, _
                OpenAfterPublish:=True
            Sheets("Bioretention").select
            'etc
            '
            '

Hope this helps!
 
Upvote 0
Solution

Forum statistics

Threads
1,224,974
Messages
6,182,106
Members
453,088
Latest member
Chaoxite

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