Step macro vs run

S

Steve Franks

When I step through the code in my macro it works perfectly, but not when I
run it.
I've noticed that some macros do not work correctly when they are run (F5).
For example this macro is supposed to copy all the items in the file
properties dialog from one document to another.
Sub XferProps()
Dim strTitle As String, strAuthor As String, strManager As String
Dim strSubject As String, strCompany As String, strCategory As String
Dim strKeywords As String, strComments As String
strTitle = ActiveDocument.BuiltInDocumentProperties(wdPropertyTitle)
strSubject = ActiveDocument.BuiltInDocumentProperties(wdPropertySubject)
strAuthor = ActiveDocument.BuiltInDocumentProperties(wdPropertyAuthor)
strManager = ActiveDocument.BuiltInDocumentProperties(wdPropertyManager)
strCompany = ActiveDocument.BuiltInDocumentProperties(wdPropertyCompany)
strCategory = ActiveDocument.BuiltInDocumentProperties(wdPropertyCategory)
strKeywords = ActiveDocument.BuiltInDocumentProperties(wdPropertyKeywords)
strComments = ActiveDocument.BuiltInDocumentProperties(wdPropertyComments)
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges

ActiveDocument.BuiltInDocumentProperties(wdPropertyTitle) = strTitle
ActiveDocument.BuiltInDocumentProperties(wdPropertySubject) = strSubject
ActiveDocument.BuiltInDocumentProperties(wdPropertyAuthor) = strAuthor
ActiveDocument.BuiltInDocumentProperties(wdPropertyManager) = strManager
ActiveDocument.BuiltInDocumentProperties(wdPropertyCompany) = strCompany
ActiveDocument.BuiltInDocumentProperties(wdPropertyCategory) = strCategory
ActiveDocument.BuiltInDocumentProperties(wdPropertyKeywords) = strKeywords
ActiveDocument.BuiltInDocumentProperties(wdPropertyComments) = strComments
End Sub

When I run it Author, Manager and Company aren't copied.

This is not the first time I've had similar problems with VBA.
Any suggestions?
Thanks
 
H

Howard Kaikow

error handling can be different between design and run modes,
verify that all properties exist.
 
H

Howard Kaikow

i would suggest puting a debug.print statement after each statement that
retrieves a propety to print tge value retrieved.

then use Run and also step by step to see what differs.
 
S

Steve Franks

I've solved the mystery.
There's nothing wrong with the code.
Word deleted the data, because the option to 'remove personal data on save'
had been set by the Remove Hidden Data tool.
Steve Franks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top