VBA Layer Visibility and ExportAsFixedFormat macro

Started by d310gece, March 24, 2015, 06:58:35 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

d310gece

Hello,
In my drawing i have command buttons named from H0 to H2 and from C0 to C3 plus H4. They all change layer visibility and printable options in all foreground page + one background page.
The code look like this:

Sub C3_Click()
Dim PagsObj As Visio.Pages
Dim pagObj As Visio.Page
Dim vsoLayer As Visio.Layer
Dim vsoLayers As Visio.Layers
'Selecting all pages for active document
Set PagsObj = ActiveDocument.Pages
'test if changeover was active
Set pagObj = PagsObj(1)
Set shps = pagObj.Shapes
Set shp = shps("sheet.252")
Set cell = shp.Cells("user.ch")
        If cell = 1 Then
        cell.Formula = "0"
        H0() = 1
        End If
    For Each pagObj In PagsObj ' iterate through the collection of pages
    'check if page is not background
    If pagObj.Background = False Or pagObj.Name = ("Bckgrnd") Then
    'Selecting all layers for active page
        Set vsoLayers = pagObj.Layers
        ' iterate through the collection of Layers
        For Each vsoLayer In vsoLayers
            If vsoLayer = ("NoCool") Then
                vsoLayer.CellsC(visLayerVisible).FormulaU = 0
                vsoLayer.CellsC(visLayerPrint).FormulaU = 0
            End If
            If vsoLayer = ("CW") Then
                vsoLayer.CellsC(visLayerVisible).FormulaU = 0
                vsoLayer.CellsC(visLayerPrint).FormulaU = 0
            End If
            If vsoLayer = ("DXcoil") Then
                vsoLayer.CellsC(visLayerVisible).FormulaU = 0
                vsoLayer.CellsC(visLayerPrint).FormulaU = 0
            End If
            If vsoLayer = ("Softcooler") Then
                vsoLayer.CellsC(visLayerVisible).FormulaU = 1
                vsoLayer.CellsC(visLayerPrint).FormulaU = 1
            End If
            If vsoLayer = ("CHO") Then
                vsoLayer.CellsC(visLayerVisible).FormulaU = 0
                vsoLayer.CellsC(visLayerPrint).FormulaU = 0
            End If
         Next
    End If
    Next
End Sub


Then I have another command button which irritate through those controls in sequence and then make a pdf after every combination. 

Sub PDFprint_Click()
Dim intCounterH As Integer
Dim intCounterC As Integer
Dim Cnumbers As String
Dim Hnumbers As String
Dim pdfname As String
    For intCounterH = 0 To 2 ' heating options
        Hnumbers = "ThisDocument." & "H" & intCounterH & "_click"
        ThisDocument.ExecuteLine (Hnumbers)
        'Sleep 1000 doesn't solve the problem
        For intCounterC = 0 To 3 'cooling options
            Cnumbers = "ThisDocument." & "C" & intCounterC & "_click"
            ThisDocument.ExecuteLine (Cnumbers)
            'Sleep 1000 doesn't solve the problem
            pdfname = "c:\print\" & Hnumbers & Cnumbers & ".pdf"
            ActiveDocument.ExportAsFixedFormat visFixedFormatPDF, pdfname, visDocExIntentPrint, visPrintAll
Sleep 8000  ' to make your macro "sleep" for one second ( 1000 milliseconds )
Next
    Next
ThisDocument.ExecuteLine ("Thisdocument.H4_Click") ' changeover
ActiveDocument.ExportAsFixedFormat visFixedFormatPDF, "c:\print\CHO.pdf", visDocExIntentPrint, visPrintAll
End Sub


Sleep function in other module:

Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long)


The problem is that when i press the button or run the code from code editor the pdf it makes is all the same (like last active combination). If I run through the code step by step (run to cursor) everything works fine. I thought that it might be related to pdf being exported to temp and only then to location, so I added sleep function but it didn't solve the problem.
Any ideas where the mistake could be ?

d310gece

Found a solution for the problem. Maybe it is not the right way to do it, but it works.  I added two lines at the end of Sub C3_Click()

Set pagObj = PagsObj(1)
    Application.ActiveWindow.SelectAll

This solves the problem, Visio stops and redraw the page and layer and only then export a PDF.
Visio.Application.ScreenUpdating = False 
Visio.Application.ScreenUpdating = True

and
Visio.Application.ShowChanges = False 
Visio.Application.ShowChanges = True

didn't helped.
Hope it helps for someone else