### Set Default Installation Folder Source: https://github.com/xarial/codestack/blob/master/solidworks-api/deployment/installer/wix/index.md Configure the default installation directory for your add-in. This example sets the path to `%programfiles%\CodeStack\MyAddIn` using `ProgramFiles64Folder` and custom directory IDs. ```xml ``` -------------------------------- ### Product.wxs Template Example Source: https://github.com/xarial/codestack/blob/master/solidworks-api/deployment/installer/wix/index.md A template for the Product.wxs file, which is central to WiX projects. It defines product details, features, and components for your installer. ```xml {% code-snippet { file-name: Product.wxs } %} ``` -------------------------------- ### Add Default Installer Dialogs in WiX Source: https://github.com/xarial/codestack/blob/master/solidworks-api/deployment/installer/wix/index.md Include standard installer dialogs such as the welcome page, installation folder selection, and progress indicator by adding UI references within the Package node. ```xml ``` -------------------------------- ### Initialize Array for Loop Examples Source: https://github.com/xarial/codestack/blob/master/visual-basic/loops/index.md Declares and initializes a string array used in subsequent loop examples. ```vb Dim arr() As String = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"} ``` -------------------------------- ### Full Add-in Implementation Example in VB.NET Source: https://github.com/xarial/codestack/blob/master/solidworks-api/getting-started/add-ins/vbnet/index.md This snippet provides a complete example of a SOLIDWORKS add-in written in VB.NET, demonstrating the structure and essential methods for add-in functionality. ```vbnet Imports SolidWorks.Interop.sldworks Imports SolidWorks.Interop.swconst Imports System.Runtime.InteropServices Public Class MySampleAddin Implements ISwAddin Private mSwApp As Object Public Function ConnectToSW(ByVal ThisSW As Object) As Boolean Implements ISwAddin.ConnectToSW mSwApp = ThisSW Dim swApp As SldWorks = DirectCast(mSwApp, SldWorks) ' Show a message box when the add-in connects to SOLIDWORKS MessageBox.Show("Hello World from MySampleAddin!") Return True End Function Public Function DisconnectFromSW() As Boolean Implements ISwAddin.DisconnectFromSW ' Perform any cleanup here Return True End Function End Class ``` -------------------------------- ### Example Macro Argument Usage Source: https://github.com/xarial/codestack/blob/master/solidworks-api/document/tables/export-table-csv/index.md This example demonstrates how to use macro arguments to export a BOM table to a specified CSV file path. ```text > -bom "D:\Tables\<_TableName_>.csv" ``` -------------------------------- ### Example: Select Float or No Mates Components Source: https://github.com/xarial/codestack/blob/master/solidworks-api/document/assembly/components/advanced-selection/index.md This example demonstrates how to select components that are either float (underconstrained) or have no mates. The OR logic is applied due to the addition of the criteria flags. ```vba Const CRITERIA As Integer = Criteria_e.Float + Criteria_e.NoMates 'All float components or components with no mates wil be selected ``` -------------------------------- ### Include EULA in WiX Installer Source: https://github.com/xarial/codestack/blob/master/solidworks-api/deployment/installer/wix/index.md Add an End User License Agreement (EULA) page to the installer. The package installation will be blocked until the user accepts the terms. The EULA must be in Rich Text Format (.rtf). ```xml ``` -------------------------------- ### Launch SOLIDWORKS Synchronously (VB.NET) Source: https://github.com/xarial/codestack/blob/master/solidworks-api/getting-started/stand-alone/connect-vbnet/index.md Launches a new SOLIDWORKS session by starting a new process. The `StartSwApp` function requires the full path to `sldworks.exe` and an optional timeout in seconds to prevent application lock-up if the process fails to start. ```vbnet Public Function StartSwApp(ByVal sldWorksPath As String, Optional ByVal timeoutSeconds As Integer = 30) As Object Dim swApp As Object = Nothing Dim startTime As DateTime = DateTime.Now Try swApp = GetObject(, "SldWorks.Application") Catch ex As Exception Dim startInfo As New ProcessStartInfo() startInfo.FileName = sldWorksPath Dim proc As Process = Process.Start(startInfo) Do While swApp Is Nothing AndAlso DateTime.Now.Subtract(startTime).TotalSeconds < timeoutSeconds Try swApp = GetObject(, "SldWorks.Application") Catch System.Threading.Thread.Sleep(100) End Try Loop End Try Return swApp End Function ``` -------------------------------- ### Install New Development Package Source: https://github.com/xarial/codestack/blob/master/angular/getting-started/package/index.md Use this command to install a new package specifically for development purposes. The '-dev' flag ensures it's added to your development dependencies. ```bash > npm i -dev new-package-name-to-install ``` -------------------------------- ### Example: Select Envelope Components Source: https://github.com/xarial/codestack/blob/master/solidworks-api/document/assembly/components/advanced-selection/index.md This example shows how to configure the macro to select only components that are marked as envelopes. This is a straightforward application of a single criterion. ```vba Const CRITERIA As Integer = Criteria_e.Envelope 'Only envelope components will be selected ``` -------------------------------- ### Add Attribution Files to WiX Installer Source: https://github.com/xarial/codestack/blob/master/solidworks-api/deployment/installer/wix/index.md Customize the installer's appearance by adding an icon, banner, and dialog background image. Ensure files are in the specified formats (.ico, .bmp) and located in a 'Resources' directory. ```xml ``` -------------------------------- ### Macro Module - Entry Point Source: https://github.com/xarial/codestack/blob/master/solidworks-api/application/documents/handle-document-save/index.md This is the main macro that starts the event monitoring. It initializes the save event handler. ```vba Option Explicit Private m_SaveEventsHandler As SaveEventsHandler Sub StartSaveMonitoring() ' Create a new instance of the handler class Set m_SaveEventsHandler = New SaveEventsHandler ' Register the handler to listen for save events m_SaveEventsHandler.RegisterEvents MsgBox "Save monitoring started." End Sub Sub StopSaveMonitoring() If Not m_SaveEventsHandler Is Nothing Then ' Unregister the handler to stop listening for save events m_SaveEventsHandler.UnregisterEvents Set m_SaveEventsHandler = Nothing MsgBox "Save monitoring stopped." End If End Sub ' This sub can be called from SOLIDWORKS Macros menu Sub Main() StartSaveMonitoring End Sub ' This sub can be called from SOLIDWORKS Macros menu Sub Cleanup() StopSaveMonitoring End Sub ' This sub is called automatically when SOLIDWORKS is closing Private Sub On_Document_Close(doc As SldWorks.Document) ' Optional: Stop monitoring if you want to reset it on each close ' StopSaveMonitoring End Sub ' This sub is called automatically when SOLIDWORKS is closing Private Sub On_Application_Shutdown() StopSaveMonitoring End Sub ``` -------------------------------- ### Add-in Class with COM Attributes Source: https://github.com/xarial/codestack/blob/master/solidworks-api/deployment/manual/index.md Example of a C# add-in class demonstrating the use of GuidAttribute, ComVisibleAttribute, and SwAddin attributes for COM registration. ```csharp [Guid("a377433e-f7cf-4a5a-9d74-b64c0c1758c2"), ComVisible(true)] [SwAddin(Description = "Sample Addin", Title = "Sample AddIn Description", LoadAtStartup = true)] public class MyAddIn : ISwAddin { ... } ``` -------------------------------- ### Example Command Line Usage Source: https://github.com/xarial/codestack/blob/master/edrawings-api/output/print-to-pdf/index.md Demonstrates how to run the exportpdf.exe tool from the command line. Specify the input folder, file filter, and optionally an output folder. ```bash > exportpdf.exe "C:\SOLIDWORKS Drawings" "*.slddrw" ``` ```bash > exportpdf.exe "C:\SOLIDWORKS Drawings" "print_*.slddrw" "C:\PDFs" ``` -------------------------------- ### DirectoryHeatTransform.xslt Example Source: https://github.com/xarial/codestack/blob/master/solidworks-api/deployment/installer/wix/index.md This is an example XSLT transformation file used with the HeatDirectory tool to exclude specific files from the installer package. ```xslt {% code-snippet { file-name: DirectoryHeatTransform.xslt } %} ``` -------------------------------- ### Sample PDM Add-In Implementation (C#) Source: https://github.com/xarial/codestack/blob/master/solidworks-pdm-api/getting-started/add-ins/debugging-best-practices/index.md A basic C# example demonstrating the structure and essential methods for a SOLIDWORKS PDM add-in. This includes initialization, handling commands, and accessing add-in properties. ```csharp using System; using System.Runtime.InteropServices; using SolidWorks.Pdm.Integration; namespace PdmHelperSampleAddIn { [Guid("YOUR-ADDIN-GUID-HERE")] [ComVisible(true)] public class PdmHelperSampleAddIn : IEdmAddIn5 { private IEdmAddInSite5 _addInSite; private int _addInID = -1; public void GetAddInInfo(ref EdmAddInInfo5 pInfo) { pInfo.வதால் = "YOUR-ADDIN-GUID-HERE"; pInfo.வதால் = "Sample Add-In"; pInfo.வதால் = "A sample add-in for SOLIDWORKS PDM."; } public void OnCmd(int nCmd, object pCmdData, out EdmCmdData outCmdData) { outCmdData = new EdmCmdData(); switch (nCmd) { case EdmCommand.uiCmdActivateAddIn: // Handle add-in activation if needed break; case EdmCommand.uiCmdAddCustomCommands: // Add custom commands here if any break; default: // Handle other commands break; } } public void OnStartup(IEdmAddInSite5 pSite, EdmInitialization pInit) { _addInSite = pSite; _addInID = pInit.வதால்; } public void OnShutdown() { // Clean up resources if necessary } } } ``` -------------------------------- ### Add-in Entry Point using SwEx.AddIn Framework Source: https://github.com/xarial/codestack/blob/master/solidworks-api/adornment/opengl/display-mode-tetrahedron/index.md This code serves as the add-in's entry point, utilizing the SwEx.AddIn framework to manage SOLIDWORKS document lifecycles through a wrapper class. ```vbnet Imports SolidWorks.AddIn. Imports SwEx.AddIn Namespace OglTetrahedron _ Public NotInheritable Class AddInAttribute Inherits SwEx.AddIn.AddInAttribute End Class _ Public Partial Class AddIn Implements ISwExAddIn End Class End Namespace ``` -------------------------------- ### Get Model Doc from Lightweight Component (VBA) Source: https://github.com/xarial/codestack/blob/master/solidworks-api/document/assembly/components/lightweight-get-model-doc/index.md Use this VBA code to get the IModelDoc2 pointer for a component. This method loads the component into memory, allowing access to its document even when it's lightweight or suppressed. Ensure you have a valid IComponent2 object to start. ```vba Dim swModel As SldWorks.SldWorks Dim swAssembly As SldWorks.AssemblyDoc Dim swComponent As SldWorks.Component2 Dim swModelDoc As SldWorks.ModelDoc2 ' Assume swModel is already initialized and swAssembly is the active assembly document ' Get the selected component (or any other way to get a Component2 object) Set swComponent = swAssembly.SelectionManager.GetSelectedObjects(swSelSWComponent).Item(1) If Not swComponent Is Nothing Then ' Get the ModelDoc2 pointer for the component Set swModelDoc = swComponent.GetModelDoc2 If Not swModelDoc Is Nothing Then ' ModelDoc2 is available, you can now access its properties MsgBox "Successfully retrieved ModelDoc2 for component: " & swComponent.Name2 ' Example: Get custom property Dim vValue As Variant vValue = swModelDoc.Extension.CustomPropertyManager("").Get("MyCustomProperty") If Not IsEmpty(vValue) Then MsgBox "Custom Property 'MyCustomProperty': " & vValue Else MsgBox "Custom Property 'MyCustomProperty' not found." End If Else ' ModelDoc2 is not available (component might be suppressed or lightweight and not loaded) MsgBox "ModelDoc2 is not available for component: " & swComponent.Name2 & ". It might be suppressed or lightweight." End If Else MsgBox "No component selected." End If ``` -------------------------------- ### Get Active Document Type (VBA) Source: https://github.com/xarial/codestack/blob/master/solidworks-api/application/documents/active-document-type/index.md Use the IModelDoc2::GetType method to retrieve the document type enumeration. This example displays the type in a message box. ```vba Sub GetActiveDocumentType() Dim swApp As Object Dim swModel As Object Dim nDocType As Long Dim strDocType As String Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc If Not swModel Is Nothing Then nDocType = swModel.GetType Select Case nDocType Case 0 ' swDocPART strDocType = "Part" Case 1 ' swDocASSEMBLY strDocType = "Assembly" Case 2 ' swDocDRAWING strDocType = "Drawing" Case Else strDocType = "Unknown" End Select MsgBox "The active document is a " & strDocType, vbInformation Else MsgBox "No active document found.", vbExclamation End If Set swModel = Nothing Set swApp = Nothing End Sub ``` -------------------------------- ### Sample PDM Add-In Implementation (VB.NET) Source: https://github.com/xarial/codestack/blob/master/solidworks-pdm-api/getting-started/add-ins/debugging-best-practices/index.md A basic VB.NET example demonstrating the structure and essential methods for a SOLIDWORKS PDM add-in. This includes initialization, handling commands, and accessing add-in properties. ```vbnet Imports System Imports System.Runtime.InteropServices Imports SolidWorks.Pdm.Integration Public Class PdmHelperSampleAddIn Implements IEdmAddIn5 Private _addInSite As IEdmAddInSite5 Private _addInID As Integer = -1 Public Sub GetAddInInfo(ByRef pInfo As EdmAddInInfo5) pInfo.வதால் = "YOUR-ADDIN-GUID-HERE" pInfo.வதால் = "Sample Add-In" pInfo.வதால் = "A sample add-in for SOLIDWORKS PDM." End Sub Public Sub OnCmd(nCmd As Integer, pCmdData As Object, ByRef outCmdData As EdmCmdData) outCmdData = New EdmCmdData() Select Case nCmd Case EdmCommand.uiCmdActivateAddIn ' Handle add-in activation if needed Case EdmCommand.uiCmdAddCustomCommands ' Add custom commands here if any Case Else ' Handle other commands End Select End Sub Public Sub OnStartup(pSite As IEdmAddInSite5, pInit As EdmInitialization) _addInSite = pSite _addInID = pInit.வதால் End Sub Public Sub OnShutdown() ' Clean up resources if necessary End Sub End Class ``` -------------------------------- ### Initialize Document Manager in C++ Source: https://github.com/xarial/codestack/blob/master/solidworks-document-manager-api/getting-started/create-connection/index.md Add the path to swdocumentmgr.dll to Project Properties->C/C++->General->Additional Include Directories. ```cpp #include "swdocumentmgr.h" // ... ISwDocumentMgrPtr dmDocMgr(__uuidof(SwDocumentMgr)); long nRetVal; // Connect to Document Manager nRetVal = dmDocMgr->Connect(_bstr_t("YOUR_LICENSE_KEY")); if (nRetVal == 0) { // Successfully connected } else { // Failed to connect } // Disconnect from Document Manager when done // dmDocMgr->Disconnect(); // dmDocMgr.Release(); ``` -------------------------------- ### CSV File Format Example Source: https://github.com/xarial/codestack/blob/master/solidworks-api/data-storage/custom-properties/link-to-file/index.md CSV file consists of 2 columns (property name and property value) without a header. If a value contains a special symbol " then the cell must have "" at the start and end of the cell value. ```text Company,Xarial Pty Limited Material,"""SW-Material""" Mass,"""SW-Mass""" ``` -------------------------------- ### Retrieve Add-in Object by GUID Source: https://github.com/xarial/codestack/blob/master/solidworks-api/getting-started/inter-process-communication/invoke-add-in-functions/via-add-in-object/index.md Retrieves a pointer to the add-in object using its GUID. This GUID must match the one defined in the add-in's `Guid` attribute. ```vb Set swGeomAddIn = swApp.GetAddInObject("{799A191E-A4CF-4622-9E77-EA1A9EF07621}") ``` -------------------------------- ### Running an npm Script Source: https://github.com/xarial/codestack/blob/master/angular/getting-started/package/index.md Demonstrates how to execute a defined npm script from the project's root directory using the command line. ```bash > npm start ``` -------------------------------- ### Specify Add-in GUID Source: https://github.com/xarial/codestack/blob/master/solidworks-api/application/add-ins/load-unload/index.md Define the Global Unique Identifier (GUID) for the add-in you wish to control. This is a mandatory constant. ```vb Const ADD_IN_GUID As String = "{1730410d-85ad-4be8-aa2d-ed977b93fe5d}" ``` -------------------------------- ### Basic SOLIDWORKS Add-in Implementation Source: https://github.com/xarial/codestack/blob/master/solidworks-api/getting-started/add-ins/csharp/index.md This is a basic implementation of a SOLIDWORKS add-in that displays a 'Hello World' message box when SOLIDWORKS starts. It requires the ISwAddin interface and COM visibility attributes. ```csharp using SolidWorks.Interop.sldworks; using SolidWorks.Interop.swpublished; using System.Runtime.InteropServices; namespace MyAddin { [ComVisible(true)] [Guid("31B803E0-7A01-4841-A0DE-895B726625C9")] [ComDefaultInterface(typeof(ISwAddin))] public class MyAddinClass : ISwAddin { public SolidWorks.Interop.sldworks.SldWorks swApp; public int ConnectToSW(object ThisSwitchIn, int cookieIn, object Reserved1, object Reserved2) { swApp = ( SolidWorks.Interop.sldworks.SldWorks)ThisSwitchIn; // The add-in is loaded and ready. System.Threading.Tasks.Task.Run(() => { System.Windows.Forms.MessageBox.Show("Hello World!"); }); return 0; } public bool DisconnectFromSW() { // The add-in is being unloaded. System.Runtime.InteropServices.Marshal.ReleaseComObject(swApp); swApp = null; return true; } } } ``` -------------------------------- ### Installing a New Package Source: https://github.com/xarial/codestack/blob/master/angular/getting-started/package/index.md Shows the command to install a new npm package and its version into your project, which will automatically update the 'dependencies' list. ```bash > npm i new-package-name-to-install ``` -------------------------------- ### Serve and Open Angular Application Source: https://github.com/xarial/codestack/blob/master/angular/getting-started/create-first-project/index.md Build and serve the Angular application, automatically opening it in the default browser. Use 'ng s' for serve and '--o' to open. ```bash > ng s --o ``` -------------------------------- ### Embed Cabinet in MSI Package Source: https://github.com/xarial/codestack/blob/master/solidworks-api/deployment/installer/wix/index.md Set `EmbedCab` to 'yes' to generate a single .msi file for your installer. This consolidates all installation files into one package. ```xml ``` -------------------------------- ### Program.cs - Main Entry Point Source: https://github.com/xarial/codestack/blob/master/solidworks-api/data-storage/custom-properties/handle-events/index.md This is the main entry point for the console application. It sets up the event handler for custom property modifications. ```csharp using System; namespace SolidWorksCustomPropertiesEvents { class Program { static void Main(string[] args) { Console.WriteLine("Starting SOLIDWORKS Custom Properties Event Handler..."); using (var handler = new CustomPropertiesEventsHandler()) { handler.StartListening(); Console.WriteLine("Listening for custom property modifications. Press Enter to exit."); Console.ReadLine(); handler.StopListening(); } Console.WriteLine("SOLIDWORKS Custom Properties Event Handler stopped."); } } } ``` -------------------------------- ### Configure Output Name Template (Multiple Placeholders) Source: https://github.com/xarial/codestack/blob/master/solidworks-api/document/sheet-metal/export-all-flat-patterns/index.md Creates sub-folders based on the 'Thickness' cut-list property and names files using assembly and part custom properties. Supports absolute paths. ```vb Const OUT_NAME_TEMPLATE As String = "D:\Output\<\$CLPRP:Thickness>\<\$ASSMPRP:ProductName>_<\[PRP:PartNo>.dwg" ``` -------------------------------- ### Instantiate and Use a Class in Visual Basic Source: https://github.com/xarial/codestack/blob/master/visual-basic/classes/index.md Create instances of a class using the 'New' keyword and assign values to its properties. Each instance maintains its own data. ```vb Dim cl1 As MyClass Dim cl2 As MyClass Set cl1 = New MyClass Set cl2 = New MyClass cl1.Var1 = "A" cl2.Var1 = "B" cl1.Var2 = 1 cl2.Var2 = 2 ``` -------------------------------- ### Get Component Pointer by Name in VBA Source: https://github.com/xarial/codestack/blob/master/solidworks-api/document/assembly/components/get-by-name/index.md Use this VBA macro to get a pointer to a component by its full name. The component name can include instance IDs and be hierarchical. ```vba Sub GetComponentByName() Dim swApp As Object Dim swModel As Object Dim swAssembly As Object Dim swComp As Object Dim vCompArr As Variant Dim i As Long Dim bRet As Boolean Dim sCompFullName As String Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc If swModel Is Nothing Then Exit Sub If swModel.GetType <> swDocASSEMBLY Then MsgBox "Please open an assembly document." Exit Sub End If Set swAssembly = swModel ' Example: Full name of a component, including instance IDs sCompFullName = "FirstLevelComp-1/SecondLevelComp-2/TargetComp-1" ' Get all components in the assembly vCompArr = swAssembly.GetComponents(True) ' True to get all components recursively ' Iterate through components to find the one by name For i = LBound(vCompArr) To UBound(vCompArr) Set swComp = vCompArr(i) If swComp.GetFullConfigurationName(False) = sCompFullName Then ' False to get the name without the configuration MsgBox "Component found: " & swComp.Name2 ' You can now use the swComp object Exit For End If Next i Set swComp = Nothing Set swAssembly = Nothing Set swModel = Nothing Set swApp = Nothing End Sub ``` -------------------------------- ### Connect to SOLIDWORKS from C# Application Source: https://context7.com/xarial/codestack/llms.txt Demonstrates two methods for connecting to SOLIDWORKS from a C# application: using Activator.CreateInstance with ProgID to start or attach, and Marshal.GetActiveObject to attach to an existing session. Method C shows how to launch a specific process and connect via the Running Object Table (ROT). ```C# // Method A – create or attach via ProgID var progType = System.Type.GetTypeFromProgID("SldWorks.Application"); var app = System.Activator.CreateInstance(progType) as ISldWorks; app.Visible = true; // Method B – attach to already-running session (throws if none exists) var app = (ISldWorks)Marshal.GetActiveObject("SldWorks.Application"); // Method C – launch a specific process and connect via ROT // Requires: reference to SolidWorks.Interop.sldworks.dll (Framework 4.0+) // Located at: \api\redist\SolidWorks.Interop.sldworks.dll // Set "Embed Interop Types" = false to avoid type-cast issues. ``` -------------------------------- ### Install Angular CLI Globally Source: https://github.com/xarial/codestack/blob/master/angular/getting-started/create-first-project/index.md Install the Angular Command Line Interface globally on your machine using npm. This command makes the Angular CLI available for all your Angular projects. ```bash > npm i -g @angular/cli ``` -------------------------------- ### Configure ProcessStartInfo to Hide Window Source: https://github.com/xarial/codestack/blob/master/solidworks-api/getting-started/stand-alone/start-background/index.md Use ProcessStartInfo with CreateNoWindow set to true and WindowStyle set to Hidden to attempt to start SOLIDWORKS invisibly. This may not always work for SOLIDWORKS. ```cs var prcInfo = new ProcessStartInfo() { FileName = appPath, CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden }; ``` -------------------------------- ### Get Sketch Snapping State (Toolbar+) Source: https://github.com/xarial/codestack/blob/master/solidworks-api/document/sketch/toggle-snapping/index.md Use this code in Toolbar+ to get the current state of the sketch snapping option. This is useful for creating toggle buttons that reflect the current setting. ```vba Return CType(Application, Object).Sw.GetUserPreferenceToggle(249) ``` -------------------------------- ### Set System Page Setup Options Source: https://github.com/xarial/codestack/blob/master/solidworks-api/options/application/system-page-setup/index.md Use this VBA code to change the system page setup options, such as paper size and scale. Ensure you have a reference to the SOLIDWORKS type library. ```vba Sub ChangeSystemPageSetup() Dim swApp As Object Dim swPageSetup As Object Dim bRet As Boolean Dim paperSize As Long Set swApp = Application.SldWorks Set swPageSetup = swApp.PageSetup ' Example: Set paper size to A4 (integer value may vary based on system settings) ' You can get the integer value for a paper size name using swPageSetup.PrinterPaperSize("A4") paperSize = swPageSetup.PrinterPaperSize("A4") ' Replace "A4" with your desired paper size name If paperSize <> -1 Then ' Check if paper size was found swPageSetup.PrinterPaperSize = paperSize Else MsgBox "Paper size 'A4' not found on this system.", vbExclamation Exit Sub End If ' Example: Set print scale swPageSetup.PrintScale = 1.0 ' 1.0 means 100% scale ' Apply system settings to the current document bRet = swApp.SetDocumentPageSetup(swPageSetup) If bRet Then MsgBox "System page setup options updated successfully." Else MsgBox "Failed to update system page setup options.", vbCritical End If Set swPageSetup = Nothing Set swApp = Nothing End Sub ```