jbiggar
03-17-2011, 11:03 AM
I am new to writing macors in Word and need help with the following:
1. Compare the ActiveDocument.Name with the numeric string in the word document.
Example ActiveDocument.Name is 1234567890.doc. I want to compare the ActiveDocument.Name with the numeric portion of thie string: Calibration Report No. 1234567890. If it is different I want a message box to say "mismatch name".
2. a message box to appear if a PDF with the ActiveDocument.name already exists as a PDF.
Here is the code that exists to save a word doc to pdf.
Sub SaveAsPDF()
Dim strFileName As String
'remove .doc or .docx from filename
If UCase(Right(ActiveDocument.Name, 1)) = "X" Then
'.docx
strFileName = Left(ActiveDocument.Name, Len(ActiveDocument.Name) - 5)
Else
'.doc
strFileName = Left(ActiveDocument.Name, Len(ActiveDocument.Name) - 4)
End If
'write the PDF file
ActiveDocument.ExportAsFixedFormat OutputFileName:=ActiveDocument.Path & "\" & strFileName & ".pdf", _
ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=False, _
OptimizeFor:=wdExportOptimizeForPrint, _
Range:=wdExportAllDocument, _
Item:=wdExportDocumentContent, _
IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, _
DocStructureTags:=True, _
BitmapMissingFonts:=True, _
UseISO19005_1:=False
'all done
MsgBox "PDF complete"
End Sub
1. Compare the ActiveDocument.Name with the numeric string in the word document.
Example ActiveDocument.Name is 1234567890.doc. I want to compare the ActiveDocument.Name with the numeric portion of thie string: Calibration Report No. 1234567890. If it is different I want a message box to say "mismatch name".
2. a message box to appear if a PDF with the ActiveDocument.name already exists as a PDF.
Here is the code that exists to save a word doc to pdf.
Sub SaveAsPDF()
Dim strFileName As String
'remove .doc or .docx from filename
If UCase(Right(ActiveDocument.Name, 1)) = "X" Then
'.docx
strFileName = Left(ActiveDocument.Name, Len(ActiveDocument.Name) - 5)
Else
'.doc
strFileName = Left(ActiveDocument.Name, Len(ActiveDocument.Name) - 4)
End If
'write the PDF file
ActiveDocument.ExportAsFixedFormat OutputFileName:=ActiveDocument.Path & "\" & strFileName & ".pdf", _
ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=False, _
OptimizeFor:=wdExportOptimizeForPrint, _
Range:=wdExportAllDocument, _
Item:=wdExportDocumentContent, _
IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, _
DocStructureTags:=True, _
BitmapMissingFonts:=True, _
UseISO19005_1:=False
'all done
MsgBox "PDF complete"
End Sub