disable macro on save

C

Charles Kenyon

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.
--
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


--------- --------- --------- --------- --------- ---------
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.
 
D

Dave Lett

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
 
M

MAT

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
 

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