Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2006

Tip: Looking for answers? Try searching our database.

disable macro on save

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MAT - 08 Feb 2006 20:54 GMT
Is it possible to delete or disable a macro when a document has been
saved?
Charles Kenyon - 08 Feb 2006 21:06 GMT
Yes.

Simpler, though, is to put the macro in the document's template and to use a
save function that attaches the new document to normal.dot or some other
template that does not contain the macro.
Signature

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://word.mvps.org/FAQs/ which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

> Is it possible to delete or disable a macro when a document has been
> saved?
Dave Lett - 08 Feb 2006 21:11 GMT
Hi,

It depends on what you really mean. You can do something like this:

If Not ActiveDocument.Saved Then
   ''do procedures before it's saved
Else
   ''do the procedures to save it
   ''or set the .Saved property to True
End If

However, any change to the document will change the .Saved property to False
until the user saves the document again; therefore the user can use the macro
again. If, however, you want the code to never be available again, then you
can use something like the following:

Public Sub test()
Dim oDelMod
Set oDelMod = VBE.VBProjects("Normal").VBComponents("DeleteModule")

If Not ActiveDocument.Saved Then
   ''do procedures before it's saved
Else
   ''delete the module holding the routine
   VBE.VBProjects("Normal").VBComponents.Remove (oDelMod)
End If

End Sub

To make this work as written, your module name has to be DeleteModule and it
has to be part of the Normal project, but you can change the names of those
as needed.

HTH,
Dave

> Is it possible to delete or disable a macro when a document has been
> saved?
MAT - 09 Feb 2006 09:34 GMT
Hi,
The problem comes because I have a macro (below) that puts document
information called from an ini file on the users C drive which works
fine until the user saves the document then opens another document from
the same program when they reopen the first documnet it now has the
second documnets details in it which is what I want to stop!
I think what you've said will work but I'm not sure where to stick it
in the code (its an inherited macro) Can you help?

Sub nofooter()
'
   With WordBasic
    .NormalViewHeaderArea Type:=0
   End With
   '
   End
End Sub
'

Sub HeaderLine()
'
   Selection.HeaderFooter.Shapes.AddLine(93.6, 57.6, 504#,
57.6).Select
   Selection.ShapeRange.Line.Weight = 2.75
   Selection.ShapeRange.Line.DashStyle = msoLineSolid
   Selection.ShapeRange.Line.Style = msoLineSingle
   Selection.ShapeRange.Line.Transparency = 0#
   Selection.ShapeRange.Line.Visible = msoTrue
   Selection.ShapeRange.Line.ForeColor.RGB = RGB(128, 128, 128)
   Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)

End Sub
Sub footerlines()
'
   Selection.HeaderFooter.Shapes.AddLine(93.6, 760#, 504#, 760#). _
       Select
   Selection.ShapeRange.Line.Weight = 3#
   Selection.ShapeRange.Line.DashStyle = msoLineSolid
   Selection.ShapeRange.Line.Style = msoLineSingle
   Selection.ShapeRange.Line.Transparency = 0#
   Selection.ShapeRange.Line.Visible = msoTrue
   Selection.ShapeRange.Line.ForeColor.RGB = RGB(150, 150, 150)
   Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
   Selection.ShapeRange.RelativeVerticalPosition = _
       wdRelativeVerticalPositionParagraph
   'Second line !!
   Selection.HeaderFooter.Shapes.AddLine(93.6, 780#, 504#, 780#). _
       Select
   Selection.ShapeRange.Line.Weight = 3#
   Selection.ShapeRange.Line.DashStyle = msoLineSolid
   Selection.ShapeRange.Line.Style = msoLineSingle
   Selection.ShapeRange.Line.Transparency = 0#
   Selection.ShapeRange.Line.Visible = msoTrue
   Selection.ShapeRange.Line.ForeColor.RGB = RGB(150, 150, 150)
   Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
   Selection.ShapeRange.RelativeVerticalPosition = _
       wdRelativeVerticalPositionParagraph
End Sub

Sub AutoOpen()
'
Dim MyDate
MyDate = Date   ' MyDate contains the current system date.
With WordBasic
maxchar = 64

' modification D B 02/09/04 if document comes from IE then load
different INI file generated
If Left(Application.ActiveDocument.Name, 10) = "IEDownLoad" Then
   Dim strIniName As String
   strIniName = Left(Application.ActiveDocument.Name, 60) & ".ini"
   Title$ = .[getPrivateProfileString$]("Document", "QWTitle",
"\\Appsrv2\QWBINI_Files\" & strIniName)
   Ref$ = .[getPrivateProfileString$]("Document", "QWref",
"\\Appsrv2\QWBINI_Files\" & strIniName)
   Rev$ = .[getPrivateProfileString$]("Document", "QWRev",
"\\Appsrv2\QWBINI_Files\" & strIniName)
   Stat$ = .[getPrivateProfileString$]("Document", "QWStat",
"\\Appsrv2\QWBINI_Files\" & strIniName)
   IDate$ = .[getPrivateProfileString$]("Document", "QWIssue",
"\\Appsrv2\QWBINI_Files\" & strIniName)
   Typ$ = .[getPrivateProfileString$]("Document", "QWTYPE",
"\\Appsrv2\QWBINI_Files\" & strIniName)
Else
   Title$ = .[getPrivateProfileString$]("Document", "QWTitle",
"qwcs.ini")
   Ref$ = .[getPrivateProfileString$]("Document", "QWref", "qwcs.ini")
   Rev$ = .[getPrivateProfileString$]("Document", "QWRev", "qwcs.ini")
   Stat$ = .[getPrivateProfileString$]("Document", "QWStat",
"qwcs.ini")
   IDate$ = .[getPrivateProfileString$]("Document", "QWIssue",
"qwcs.ini")
   Typ$ = .[getPrivateProfileString$]("Document", "QWTYPE",
"qwcs.ini")
End If
   '
   ' Get next issue date from RC ini file
   NIDate$ = .[getPrivateProfileString$]("Document", "Nissue",
"\\appsrv1\qwb_pro\master\RC.ini")
   '
End With
   ' check for short or long date format
   Dim Findspace
   Findspace = Mid(IDate$, 9, 1)
   If Findspace = " " Then IDate$ = Left(IDate$, 8) Else IDate$ =
Left(IDate$, 10)
   '
   ' Check to see if document status is ISSUED
    Dim Issuestatus
    Issuestatus = Mid(Stat$, 1, 6)
   If Issuestatus <> "ISSUED" Then IDate$ = ""
   '
With WordBasic
With ActiveDocument.PageSetup
       '
       .FooterDistance = 35
End With
header:
.StartOfDocument
.NormalViewHeaderArea Type:=0
.EditSelectAll
.WW6_EditClear
.Font "Arial"
.FormatFont Points:=14, Bold:=1, Italic:=0, Color:=0
.Insert " " + Title$
Call HeaderLine
'.StartOfDocument
'
footer:
'.StartOfDocument
.NormalViewHeaderArea Type:=0
.Font "Arial"
.NormalViewHeaderArea Type:=1
.EditSelectAll
.WW6_EditClear
.Font "Arial"
.FormatFont Points:=8, Bold:=0, Italic:=1, Color:=0
.InsertPara
'
'Can't use word basic for this
End With
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
   '
   ' check to see if the document is a form, and if it is then exit !
   '
   'If Typ$ = "Form (F)" Then Call nofooter Else
   With WordBasic
   .Insert "Document administered by WPro. Uncontrolled copies valid
until the next document issue on " + NIDate$
   .InsertPara
   .InsertPara
   '.CharRight 100
   .Font "Arial"
   .FormatFont Points:=8, Bold:=1, Italic:=0, Color:=0
   .Insert "HFL " + Ref$
   .Insert Chr(9) + "Revision " + Rev$
   .Insert Chr(9) + "Page Number "
   .InsertField Field:="page \*arabic"
   .Insert " of "
   .InsertField Field:="numpages"
   .CharRight 10
   .InsertPara
   .Insert "Status: " + Stat$ + " (" + IDate$ + ")"
   .Insert Chr(9) + "Issuing Authority: System Administrator"
   .Insert Chr(9) + "Date Printed "
   Selection.InsertDateTime
   Call footerlines
   .NormalViewHeaderArea Type:=0
End With
End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.