The document outlines a VBA script for generating reports in PDF or Word format from a Word document. It includes error handling, functions for adding report sections, and retrieving project and model information. The report contains details such as project name, client, engineer, and a summary of model components.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
4 views1 page
Grasp
The document outlines a VBA script for generating reports in PDF or Word format from a Word document. It includes error handling, functions for adding report sections, and retrieving project and model information. The report contains details such as project name, client, engineer, and a summary of model components.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1
Case "PDF"
wordDoc.ExportAsFixedFormat reportPath & ".pdf", 17 ' 17 = PDF
wordDoc.Close False wordApp.Quit MsgBox "PDF report generated successfully", vbInformation, "GRASP" Case Else wordDoc.SaveAs2 reportPath & ".docx" MsgBox "Word report generated (unknown format requested)", vbInformation, "GRASP" End Select
Exit Sub
ErrorHandler: MsgBox "Error generating report: " & Err.Description, vbCritical, "GRASP Error" On Error Resume Next wordDoc.Close False wordApp.Quit End Sub
' Add section to report
Sub AddReportSection(wordDoc As Object, title As String, content As String) With wordDoc.Content .InsertAfter title & vbCrLf .InsertAfter content & vbCrLf & vbCrLf .Paragraphs(.Paragraphs.Count - 1).Range.Font.Bold = True .Paragraphs(.Paragraphs.Count - 1).Range.Font.Size = 14 End With End Sub
' Get project information
Function GetProjectInfo() As String Dim info As String info = "Project Name: " & ThisWorkbook.Worksheets("Project Info").Range("B1").Value & vbCrLf info = info & "Client: " & ThisWorkbook.Worksheets("Project Info").Range("B2").Value & vbCrLf info = info & "Engineer: " & ThisWorkbook.Worksheets("Project Info").Range("B3").Value & vbCrLf info = info & "Date: " & Format(Date, "yyyy-mm-dd") & vbCrLf info = info & "Software: GRASP v2.0" & vbCrLf GetProjectInfo = info End Function