Hi. I have this code to insert the current date into a blank document. However, I would like to tweak it so that it replaces text with and ID of "Date". This should be easy but I'm still a little lost on how to do this.
Sub InsertDate() ' Get the current date Dim currentDate As String currentDate = Format(Date, "mm/dd/yyyy") ' Or use your desired format ' Get the active document Dim activeDoc As Object Set activeDoc = ActiveDocument ' Get the active layer Dim activeLayer As Object Set activeLayer = activeDoc.ActiveLayer ' Create a text object Dim textObject As Object Set textObject = activeLayer.CreateArtisticText(0, 0, currentDate) ' Position the text object (adjust as needed) textObject.PositionX = 10 ' Example: 10 mm from the left edge textObject.PositionY = 10 ' Example: 10 mm from the top edgeEnd Sub
I tried this but no luck.
Sub DateInsert2()Dim p As PageDim currentDate As StringDim activeLayer As Object Set activeLayer = activeDoc.activeLayercurrentDate = Format(Date, "mm/dd/yyyy")activeLayer.FindShape(Date).Text.Story = activelayer.Name currentDate'ActivePage.Name = "__" & activeLayer.FindShape("sku").Text.StoryEnd Sub
You try to look here
https://community.coreldraw.com/talk/coreldraw_graphics_suite_x6/f/coreldraw-graphics-suite-x6/50547/i-am-looking-for-a-way-to-make-coreldraw-x6-automatically-insert-the-current-time-and-date-into-a-specific-area-on-a-drawing/240510#240510
Thank you. It was a bugger trying to figure out the exact position for the updated date but I got it. Is there a way to grab the object position and pop up a message box showing the coords?
here is the altered code:
Sub IDAT()Dim DAT As Shape, x#, y#ActiveDocument.Unit = cdrMillimeterActivePage.FindShapes(Name:="date").Deletex = 317 'position of text with a system date and timey = 39.5 'position of text with a system date and timeSet DAT = activeLayer.CreateArtisticText(x, y, Date & " ", cdrEnglishUS, , "Calibri", 9, , , , cdrLeftAlignment)DAT.Fill.UniformColor.CMYKAssign 0, 0, 0, 100DAT.Name = "date"End Sub
you can try code below
Sub IDAT()Dim DAT As Shape, x#, y#, sr As ShapeActiveDocument.Unit = cdrMillimeterSet sr = ActivePage.FindShape(Name:="date")sr.GetPositionEx cdrBottomLeft, x, yMsgBox ("position x = " & x & vbCr & "position y = " & y)sr.Delete'x = 317 'position of text with a system date and time'y = 39.5 'position of text with a system date and timeSet DAT = ActiveLayer.CreateArtisticText(x, y, Date & " ", cdrEnglishUS, , "Calibri", 9, , , , cdrLeftAlignment)DAT.Fill.UniformColor.CMYKAssign 0, 0, 0, 100DAT.Name = "date"End Sub
This is great. Can you strip this down to a macro that only gets the object position with msg box? I tried and broke it.