I'm trying to create a macro that will pop up a input box where you can enter the x coord and create a vertical guideline at that location. So far I can get the input to pop up, but after that I get no errors but the guideline is not created. Here's the code I'm currently using. Any suggestions would be greatly appreciated.
Sub CreateGuidelineAtXCoord() Dim xCoord As Double Dim activePage As Page
' Get the active page Set activePage = ActiveDocument.activePage
' Prompt the user for the X-coordinate xCoord = InputBox("Enter X-coordinate for the guideline:", "Create Guideline")
' Check if the user entered a valid number If IsNumeric(xCoord) Then ' Create a vertical guideline at the specified X-coordinate activePage.CreateGuideline cdrVerticalGuideline, xCoord Else ' Display a message if the user entered an invalid X-coordinate MsgBox "Invalid X-coordinate entered. Please enter a numeric value.", vbExclamation, "Macro Error" End IfEnd Sub
activePage.GuidesLayer.CreateGuide xCoord, 1, xCoord, -1 Layer.CreateGuide method - Developer Area - CorelDRAW Community
oractivePage.GuidesLayer.CreateGuideAngle xCoord, 0, 90Layer.CreateGuideAngle method - Developer Area - CorelDRAW Community
Thanks for your quick response. Both of those suggestions are working.
However 1 unit equals 1 inch, I work in mm. To fix this, is it a setting within CD or a VBA code fix?
You can set the document to millimeters or convert the value to millimeters
Document.Unit property - Developer Area - CorelDRAW Community
Application.ConvertUnits method - Developer Area - CorelDRAW Community
I opted to convert the value. I did change the document to mm, however that kept resetting to inches when opening a new workspace. Then I had to set it back to mm. For what I need the macro for the conversion works very well.