Show pages that have active layer only

Started by bangzii75, February 28, 2019, 02:53:37 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

wapperdude

#15
This should do it.  You need to edit 2nd subroutine to change the name of the temporary file.  You can also code in a different file path if desired.

Run the first macro to hide the pages.  It will call the 2nd macro which will first save a temporary file with name you provide.  Then delete pages based upon visibility. Re-save.  Then export to PDF. 


Sub SrchLayers()
    Dim vsoPg As Visio.Page
    Dim pgLay As Visio.Layer
    Dim visLayCnt As Double
   
    For Each vsoPg In ActiveDocument.Pages
       visLayCnt = 0
       If vsoPg.Background = False Then
            ActiveWindow.Page = vsoPg
            For Each pgLay In vsoPg.Layers
                If pgLay.Name <> "flrPlan" Then
                    If pgLay.CellsC(visLayerVisible).ResultStr(visNone) = "1" Then
                        visLayCnt = 1
                    End If
                End If
            Next
        End If
        If visLayCnt = 0 And vsoPg.Name <> "Page-1" Then
            vsoPg.PageSheet.CellsU("UIVisibility").FormulaU = 1
        Else
            vsoPg.PageSheet.CellsU("UIVisibility").FormulaU = 0
        End If
    Next
    ActiveWindow.Page = ActiveDocument.Pages(1)
   
    Call TmpFile
   
End Sub

Sub tmpFile()
    Dim pgCnt As Integer
    Dim docPath As Variant
    Dim tmpFile As String
   
    docPath = ActiveDocument.Path
    tmpFile = "DeleteMeHidePg"

    ActiveDocument.SaveAsEx docPath & tmpFile & ".vsdm", visSaveAsWS + visSaveAsListInMRU
    pgCnt = ActiveDocument.Pages.Count
   
    For i = pgCnt To 1 Step -1
        Set vsoPg = ActiveDocument.Pages(i)
        If vsoPg.Background = False Then
            If vsoPg.PageSheet.CellsU("UIVisibility").ResultStr(visNone) = "1" Then
               vsoPg.Delete (1)
            End If
        End If
    Next
    ActiveDocument.Save
    ActiveDocument.ExportAsFixedFormat visFixedFormatPDF, docPath & tmpFile & ".pdf", visDocExIntentPrint, visPrintAll, 1, 2, False, True, True, True, False
End Sub
Visio 2019 Pro

bangzii75

Dear Wapperdude,

Thank you so much. By running the code, the visio original file will be closed and will open the temporary visio file. How to have the original visio file keep open, I do not need to have the temporary visio file open, I do not need the temporary visio file actually, but also how to have the pdf output open. At the moment I need to go to the folder and open it.

Please advise.

Many thanks.

wapperdude

#17
Here's one method to open the PDF after saving.  I include the save as PDF line for completeness.

Sub saveNopen PDF()
    ActiveDocument.ExportAsFixedFormat visFixedFormatPDF, "C:\some path\some file.pdf", visDocExIntentPrint, visPrintAll, 1, 2, False, True, True, True, False
    ActiveDocument.FollowHyperlink "C:\some path\some file.pdf", "Page-1"
End Sub



With regards to the tmp Visio file, as long as you have a backup for the original, skip the save as tmp file steps.  Just loop thru and delete pages, then save as PDF.  Once PDF is saved you can
1) close Visio without saving and re-open

or
2) loop thru the pages and set UIVisibility to 0...I think that should work...to see all of the pages.  Then, if you have some other "hidden" agenda, you can make your visibility changes and run save as PDF again.
Visio 2019 Pro