M
MAT
Hi,
I have a macro (below) that puts document
information in the header and footers of a document from an external
application which works
fine until the user saves the document then opens another document from
the same program when they subsequently reopen the first documnet it
now has the
second documents details in it which is what I want to stop! (The
information is written to the persons ini file on their C drive)
Is there any way to stop the macro from running once the document has
been saved? all the documents start with a name ~qw if thats any help.
The user can also open the documents from the intranet which doesn't
cause the same problem.
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
I have a macro (below) that puts document
information in the header and footers of a document from an external
application which works
fine until the user saves the document then opens another document from
the same program when they subsequently reopen the first documnet it
now has the
second documents details in it which is what I want to stop! (The
information is written to the persons ini file on their C drive)
Is there any way to stop the macro from running once the document has
been saved? all the documents start with a name ~qw if thats any help.
The user can also open the documents from the intranet which doesn't
cause the same problem.
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