We help IT Professionals succeed at work.
Get Started

Visio macro

timbrigham
timbrigham asked
on
429 Views
Last Modified: 2012-05-09
I have a background page which I would like to update a field in on closing the document. At current I'm using code which updates the document on opening, but it gives an inaccurate impression of when the document was last modified as a result.

I thought all I needed to do was replace
Document_DocumentOpened with Document_BeforeDocumentClose in my code, but that doesn't work, giving a run time eror 91 since I don't have an ActiveDocument. Please help.
Private Sub Document_DocumentOpened(ByVal doc As IVDocument)
    Dim shp As Shape
    Dim pg As Page
    Dim sUsername As String
    sUsername = Environ("username")         ' Windows username
    
    For Each pg In ActiveDocument.Pages
        If pg.Background = True Then
            For Each shp In pg.Shapes
                    If shp.CellExists("Prop.Username", False) Then
                        shp.Cells("Prop.Username").FormulaU = _
                            Chr(34) & sUsername & Chr(34)
                    End If
            Next
        End If
    Next 
End Sub

Open in new window

Comment
Watch Question
Visio Consultant, Trainer, Author, and Developer
CERTIFIED EXPERT
Most Valuable Expert 2011
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE