PDA

View Full Version : Excel and Coreldraw



loppydog
12-07-2012, 11:50 AM
Hi guys, I am new to VBA scripting, and I was hoping to get some help here. this is what I am trying to do: I would like to create a VBA macro within CorelDraw to grab info from an Excel spreadsheet that I have already created. The Excel file is pretty simple with 1 column and 96 rows, but not all 96 cell will always be populated. I was thinking it would go something like this: I already have my Corel template open, when I start the macro it would open the excel file(same location) and check to see if cell A1 has any info. If it does, it would copy the contents from that cell and paste it to a location on my corel template(x=0.500, y=0.100). Then it would check A2, and paste it to a different loacation(x=500, y=0.300) ect, ect. If it detects a cell with no info it will finish the script. Another idea would be to have a user box come up asking how many cells down to check before it closes the script(8 of 96).

I hope that a script like this might be easy for someone here to whip up for me...I would appreciate it a whole lot!!

p45cal
12-09-2012, 03:07 AM
I'd be interested in exploring this with you (I didn't realise that CorelDraw had VBA!)
I used to play with CorelDraw a fair bit a few years ago; I haven't kept up with the various versions (I have X3 on an xp machine). I've just done some Googling for CorelDraw VBA and there isn't a lot, I explored recording a few macros in CorelDraw and had a peep at its object model. While 'whip up' would not be a good description of how I could help you, we could probably muddle through.

A description of what you're trying to achieve (what information is in the cells of the spreadsheet, what would you paste into your Corel template etc. etc.)

Can you point me to some resources on the internet too?

Finally, since you're coding in CorelDraw and not Excel, perhaps there is a better place to discuss this?

loppydog
12-10-2012, 08:16 AM
hi p45cal, I found a VBA script that might be very helpful for you. I tried to look it over and extract any related code, but I am just too unfamiliar with all of it. This script is somewhat close to what I am looking for, but just over complex. I was trying to strip it down to the bear minimum and take out all the extra user input. Anyway, if you get a chance download the CDR and the XLS from this link and play around with it and see what you think. Thanks!

h**p://corel-vba.awardspace.com/From_Excel.htm

sorry I cannot post links yet ;)

Kenneth Hobs
12-10-2012, 10:50 AM
You need to post the VBA code. Most here do not have CorelDraw.

As p45cal said, a CorelDraw forum would be the best place for CorelDraw VBA questions. I doubt there are many though.

Obviously, it is easy for us to show you how to set an Excel range dynamically. e.g.
Sub t()
Dim r As Range
With Workbooks(ThisWorkbook.Name).Worksheets("Sheet1")
Set r = .Range("A2", .Range("A" & Rows.Count).End(xlUp))
End With

MsgBox r.Address
End Sub

Since you are handling Excel through an object reference in the VBA for CorelDraw, you need to prefix Workbooks with that object and replace ThisWorkbook.Name with the name of the Excel Workbook. I would imagine that the CorelDraw code example would show that though.

loppydog
12-10-2012, 11:14 AM
Here is the sample VBA done for corelDraw. I figure there is enough info here to do what I would like to do, but its all "Greek" to me. I looked into posting on a different forum/section, but this one was the only related section that actually had people visiting it.


Option Explicit

'This VBA procedure is long because it has many comments & there are options.
'In your particular use you may not need all the options.
'You can strip away many of the unnecessary comments.
'The Sub FILL_COLOR and all references to it can be deleted if you do not want a uniform colored background.

'This document has a Master Layer that can be removed from the Object Manager if not needed.
'I provide the Master Layer to show one way of how to have non-variable objects on each page.
'Remember that objects on the Master Layer are always on top of objects on other page layers.
'This means that Master Layer objects can obsure variable data.

Dim DATA(10000, 2)
'The data array here allows 10,000 sets of data.
'If more data sets are supplied in the data file, increase the 10000 to a larger number.
'The second variable in the array ie 2 is the number of variables in each data set less 1.
'ie I have used 3 columns of data in the Excel Worksheet, so Dim DATA(10000, 2).
'If you have only 1 variable in a data set then Dim DATA(10000,0).
'If you have 10 variables in a data set then Dim DATA(10000,9).

'The data file I have supplied has a header in each column located in row 1.
'So the first piece of data cells(2,1) will go into DATA(1,0).
'I know that there is DATA(0,0) but I have not used it to make it easy.
'DATA(1,0) will contain Cells(2,1)
'DATA(1,1) will contain Cells(2,2)
'DATA(1,2) will contain Cells(2,3)

'DATA(2,0) will contain Cells(3,1)
'DATA(2,1) will contain Cells(3,2)
'DATA(2,2) will contain Cells(3,3)

'And so on.

'This stores the name of the file that contains the data.
'The excel file must be in the same folder as this CorelDraw file.
Dim EXCEL_DATA_FILE As String

Sub START()

Dim shDATA_OBJECT As Shape
Dim STRING1 As String
Dim OBJECT_COUNTER As Integer
Dim OBJECT_POSITION_COUNTER As Integer
Dim No_COLUMNS As Byte
Dim No_ROWS As Byte
Dim sngEDGE_TO_COLUMN As Single
Dim sngEDGE_TO_ROW As Single
Dim X_STEP As Single
Dim Y_STEP As Single
Dim PAGE_ORIENTATION As String
Dim sngDATA_OBJECT_X_Pos As Single
Dim sngDATA_OBJECT_Y_Pos As Single

OBJECT_COUNTER = 0
OBJECT_POSITION_COUNTER = 0

MsgBox ("Locate the Excel file to the same location as this CorelDraw file")

10 PAGE_ORIENTATION = InputBox("What is the page orientaion? Portrait or Landscape?")
'Convert the input into all the same case before checking whether portrait or landscape are required.
'If not then Portrait, portrait or PORTRAIT will be different.
PAGE_ORIENTATION = UCase(PAGE_ORIENTATION)

'If Cancel has been selected then end
If PAGE_ORIENTATION = "" Then
End
Else
'Now alter the page to suit to portrait or landscape.
If PAGE_ORIENTATION = "PORTRAIT" Then
PAGE_ORIENTATION = cdrPortrait
ActiveDocument.ActivePage.Orientation = PAGE_ORIENTATION
Else
If PAGE_ORIENTATION = "LANDSCAPE" Then
PAGE_ORIENTATION = cdrLandscape
ActiveDocument.ActivePage.Orientation = PAGE_ORIENTATION
Else
MsgBox ("There has been a spelling error!")
GoTo 10
End If
End If
End If

sngEDGE_TO_COLUMN = InputBox("What distance from left edge?")

sngEDGE_TO_ROW = InputBox("What distance from bottom edge?")

'This is asking for the horizontal pitch, or the horizontal space between each set of variable data.
X_STEP = InputBox("What horizontal step distance?")
'This is asking for the vertical pitch, or the verticall space between each set of variable data.
Y_STEP = InputBox("What vertical step distance?")

No_COLUMNS = InputBox("How many columns on each page are to be printed?")
No_ROWS = InputBox("How many rows on each page are to be printed?")

'What is the name of the data file.
EXCEL_DATA_FILE = InputBox("What is the name of the Excel data file?")

'Now open Excel, create an array from the data file and close Excel.
'Reading all the data at once rather than row by row as needed as has 2 advantages.
'1 It is quicker to read the data all at once rather than swapping between CorelDraw & Excel to get data.
'2 If you force the macro to close after the data has been read there will be no hidden Excel application still running.
GET_DATA

'Make Corel Draw the visible application.
CorelDRAW.Visible = True

'Fill a uniform fill is required as a background remove the apostrophy from the next line and also about 10 lines below.
'FILL_COLOR

While DATA(OBJECT_COUNTER + 1, 1) <> ""

OBJECT_POSITION_COUNTER = OBJECT_POSITION_COUNTER + 1

OBJECT_COUNTER = OBJECT_COUNTER + 1

'Here I combine all the text into 1 text string with line breaks for convenience in handling.
'Alternatively you can create several text strings.
'Two text strings or objects for each data set will mean creating a second data object such as shDATA_OBJECT2.
'See towards the end of this Sub where I discuss how to control the position of shDATA_OBJECT2.
STRING1 = DATA(OBJECT_COUNTER, 0) & vbCrLf & DATA(OBJECT_COUNTER, 1) & vbCrLf & DATA(OBJECT_COUNTER, 2)

'Check whether a new page is required. If so create a new page.
If OBJECT_COUNTER - (No_COLUMNS * No_ROWS) * Int((OBJECT_COUNTER - 1) / (No_COLUMNS * No_ROWS)) = 1 Then
OBJECT_POSITION_COUNTER = 1
If OBJECT_COUNTER <> 1 Then
ActiveDocument.AddPages (1)
ActiveDocument.ActivePage.Orientation = PAGE_ORIENTATION
'Fill a uniform fill is required as a background remove the apostrophy from the next line & also about 10 lines above.
'FILL_COLOR
End If
End If


'Position the new text at 0,0.
Set shDATA_OBJECT = ActiveLayer.CreateArtisticText(0, 0, STRING1)
shDATA_OBJECT.Text.FontProperties.Name = "Arial"
shDATA_OBJECT.Text.FontProperties.Size = 10
shDATA_OBJECT.Text.FontProperties.Style = cdrNormalFontStyle '= cdrBoldFontStyle
shDATA_OBJECT.Text.AlignProperties.Alignment = cdrCenterAlignment


'If the text has all the same format delete this section.
'Here I show how to format a portion of the text string.
'Where the text "FULL MEMBER" occurs in the first line it is to be bold.
'If it exists in the first line of the particular data then make the first line bold.
'The first line of text in CorelDraw has a cariage return, a non-printing character, following it.
'I only look at the first 11 characters because "FULL MEMBER" has 11 characters including any spaces.
If Left(shDATA_OBJECT.Text.Story.Lines(1).Text, 11) = "FULL MEMBER" Then
shDATA_OBJECT.Text.Story.Lines(1).Bold = True
End If

'If the a line line of text say the first line, is a special size and is bold compared to the other lines.
'shDATA_OBJECT.Text.Story.Lines(1).Size = 26
'shDATA_OBJECT.Text.Story.Lines(1).Bold = True

'Dark Green text.
'It is possible to read these color numbers from the data file & so have variable colors.
'Specify text color using CMYK color.
'In this example 85 parts of Cyan (Blue), 0 parts Magenta (Red), 100 parts Yellow & 55 parts Black.
'You can only use up to 100 parts of anyone color.
'As a tip for digital printing do not use any more than a total of 300 parts for all 4 colors.
shDATA_OBJECT.Fill.UniformColor.CMYKAssign 85, 0, 100, 55
'For Black text use.
'shDATA_OBJECT.Fill.UniformColor.CMYKAssign 0, 0, 0, 100

'Alternatively specify text color using RGB color.
'In this RGB example 83 parts of Red, 111 parts Green & 89 parts Blue.
'shDATA_OBJECT.Fill.UniformColor.RGBAssign 83, 111, 89


'Reposition the data object to its correct position.
'First calculate the new x coordinate.
sngDATA_OBJECT_X_Pos = (sngEDGE_TO_COLUMN / 25.4) - shDATA_OBJECT.SizeWidth / 2 _
+ X_STEP * ((OBJECT_POSITION_COUNTER - 1) _
- No_COLUMNS * Int((OBJECT_POSITION_COUNTER - 1) / No_COLUMNS)) / 25.4

'First calculate the new y coordinate.
'Here I have used the Excel function WorksheetFunction.RoundDown and so VBA must reference Microsoft Excel.
'This is not a problem here as the data source is Excel.
'If the data source was something else and you did not want to reference Excel or did not have Excel on the computer
'then you would have to truncate or round in the formula using another method.
sngDATA_OBJECT_Y_Pos = ((sngEDGE_TO_ROW + Y_STEP * (No_ROWS - 1)) / 25.4) _
+ shDATA_OBJECT.SizeHeight / 2 _
- Y_STEP * WorksheetFunction.RoundDown((OBJECT_POSITION_COUNTER - 1) / No_COLUMNS, 0) / 25.4

'Now position the data.
shDATA_OBJECT.SetPosition sngDATA_OBJECT_X_Pos, sngDATA_OBJECT_Y_Pos

'If you need to position more data in the same set,
'it can be positioned relative to sngDATA_OBJECT_Y_Pos & sngDATA_OBJECT_Y_Pos
'eg shDATA_OBJECT2.SetPosition sngDATA_OBJECT_X_Pos + 0.3, sngDATA_OBJECT_Y_Pos + 0.5
'Here shDATA_OBJECT2 represents another object.
'It will be positioned 0.3 inches to the right & 0.5 inches higher for each set of data.
Wend

End Sub


Sub GET_DATA()

Dim EXCELAPP As Object
Dim ROW_COUNTER As Integer

Set EXCELAPP = CreateObject("excel.application")
'Make Excel invisible.
EXCELAPP.Visible = False

'Now open the Excel file that is located in the same folder as this CorelDraw fie.
Workbooks.Open (ActiveDocument.FilePath & EXCEL_DATA_FILE)

'The following line can be used if the Excel file is on Fred's Desktop whilst the CorelDraw file can be anywhere on the same computer.
'Workbooks.Open ("C:\Documents and Settings\Fred\Desktop\" & EXCEL_DATA_FILE)

'Now assign the spreadsheet data to the array.
ROW_COUNTER = 1
'To ensure we read all the data in all 3 spreadsheet columns the while statement must check each column for data.
'If there was only one column of data then it would be;
'While cells(ROW_COUNTER + 1,......
'Note that we use cells(ROW_COUNTER + 1) in this While loop.
'This is because the first row of the spreadsheet is a header & so is not read.
'If you do not have a header use cells(ROW_COUNTER,...... in place of cells(ROW_COUNTER,..... ie Do not use + 1
While cells(ROW_COUNTER + 1, 1) <> "" Or cells(ROW_COUNTER + 1, 2) <> "" Or cells(ROW_COUNTER + 1, 3) <> ""
DATA(ROW_COUNTER, 0) = cells(ROW_COUNTER + 1, 1)
DATA(ROW_COUNTER, 1) = cells(ROW_COUNTER + 1, 2)
DATA(ROW_COUNTER, 2) = cells(ROW_COUNTER + 1, 3)
ROW_COUNTER = ROW_COUNTER + 1
Wend

'Close excel.
Excel.Application.Workbooks.Close

'Reset Excel's visiblity.
EXCELAPP.Visible = True

'Close Excel.
EXCELAPP.Quit

End Sub


Sub FILL_COLOR()
'This is an option if a uniform background color is required.
'The Master Layer can manually be removed if not needed.
Dim shRECTANGLE As Shape
'Draw a rectangle the same size as the paper.
Set shRECTANGLE = ActiveLayer.CreateRectangle(0, ActiveDocument.ActivePage.SizeHeight, ActiveDocument.ActivePage.SizeWidth, 0, 0, 0, 0, 0)

'Specify background color using CMYK color. This color is yellow.
shRECTANGLE.Fill.UniformColor.CMYKAssign 0, 0, 100, 0
'Alternatively specify text color using RGB color.
'shDATA_OBJECT.Fill.UniformColor.RGBAssign 255, 254, 0

End Sub

p45cal
12-10-2012, 11:22 AM
I'll look at this tonight (in a few hours time) or tomorrow.

loppydog
12-10-2012, 11:48 AM
Perfect thanks a bunch!

p45cal
12-10-2012, 05:39 PM
OK, I've run through that link and run the cdr macro and am ready to go.
Now, what do you want to do with the data in the Excel sheet?
What kind of data is it?
Where's it going to go in Corel?
So a fair bit more information needed.

bedtime for me now in the UK.

loppydog
12-11-2012, 09:25 AM
OK, I suppose it would be best to just upload what I have so far, that way we are on the same page. So here is what I have:

I have an Excel worksheet named "DATABASE.xlsx" in the same folder as my CorelDraw project "PUSHRODS.cdr". I have 96 cells in Excel that I need to pull data from (A2-A97). The data in the cells are formatted as a number.

So I am thinking we will just start with something relatively easy. Lets copy the info from cell A2 to the position X5.75 Y-0.475. Then we will copy the data from cell A3 to the position X5.75 Y-1.025. I think that will be a good starting point for now. Obviously I will need to fill in the rest of the 96 spaces and have some checks in place to see if there are empty cells.

Please let me know if this is enough info to get you going. Also let me know if you have trouble opening the files. Thanks!

h**p://wikisend.com/download/316310/DATABASE.zip

**EDIT** I updated my Excel to allow for blank cells for blank lengths...shouldn't change anything with the VBA script.

p45cal
12-11-2012, 11:50 AM
Please let me know if this is enough info to get you going. Also let me know if you have trouble opening the files.
Yes, can't open pushrods.cdr; I have got CorelDraw!X3 (2005), nothing later.

Anyway, this macro for CorelDraw using some code from above (though I will make it more robust later (using an existing instance of Excel if there is one, not trying to open the file if it's already open, perhaps being a bit more sophisticated about the range that data is grabbed from and…) grabs the contiguous data from A2 downwards from the Excel file called Database.xlsx in the same folder as the corel graphic file and places the strings in the corel graphic, using the coordinates you supplied but continues downward in steps of -.55.
This places the strings mostly off my document, bottom right (probably because my document ref. point is in the bottom left hand corner).
Something to whet your appetite.Sub blah1()
Dim EXCELAPP As Object
Set EXCELAPP = CreateObject("excel.application")
EXCELAPP.Visible = True

Set ExcelWkBk = EXCELAPP.Workbooks.Open(ActiveDocument.FilePath & "DataBase.xlsx")
With ExcelWkBk.sheets("Sheet1")
x = .Range(.cells(2, 1), .cells(2, 1).End(-4121))
End With
ExcelWkBk.Close SaveChanges:=False
EXCELAPP.Quit
yPos = -0.475
For Each myStr In x
ActiveLayer.CreateArtisticText 5.75, yPos, myStr
yPos = yPos - 0.55
Next myStr
End Sub

loppydog
12-11-2012, 12:25 PM
yes indeed! that is a very good start! Sorry about the incompatible Coreldraw file...try the one I post below. There are a couple issues that i think will be easy to fix

1: the text needs to be centered to that location(seems to be using bottom left "handle")
2: I need it to be a specific font type and size
3: If you are able to open my Coreldraw file you will see that I have 3 columns of 32 pcs, not one column of 96.
4: If it detects and empty cell I get an error "parameter text cannot be an empty string"

you have been such a HUGE help!

h**p://wikisend.com/download/654002/COREL DRAW 11.cdr

p45cal
12-11-2012, 02:37 PM
yes indeed! that is a very good start! Sorry about the incompatible Coreldraw file...try the one I post below. There are a couple issues that i think will be easy to fix

1: the text needs to be centered to that location(seems to be using bottom left "handle")
2: I need it to be a specific font type and size
3: If you are able to open my Coreldraw file you will see that I have 3 columns of 32 pcs, not one column of 96.
4: If it detects and empty cell I get an error "parameter text cannot be an empty string" 1. Dealt with below
2. Dealt with below but adjust to suit
3. Dealt with below (I note that the three column centres don't seem to be equidistant)
4. There shouldn't be an empty cell. At the moment only column A is looked at in the excel spreadsheet. I'm not sure what relevance adjusting the layout in the other columns has?
edit post posting: I get it, there are formulae referring to other cells.

Note that my corel version is X3 (version 13).
Sub blah1()
Dim EXCELAPP As Object
Set EXCELAPP = CreateObject("excel.application")
EXCELAPP.Visible = True

Set ExcelWkBk = EXCELAPP.Workbooks.Open(ActiveDocument.FilePath & "DataBase.xlsx")
With ExcelWkBk.sheets("Sheet1")
x = .Range(.cells(2, 1), .cells(2, 1).End(-4121))
End With
ExcelWkBk.Close SaveChanges:=False
EXCELAPP.Quit

ActiveDocument.ReferencePoint = cdrCenter
ypos = -0.475
xpos = 5.75
Count = 1
For Each myStr In x
Set zz = ActiveLayer.CreateArtisticText(Left:=0, Bottom:=0, Text:=myStr, Font:="Arial", Size:=16)
zz.SetPosition xpos, ypos
ypos = ypos - 0.55

If (Count) Mod 32 = 0 Then
xpos = Choose(Count / 32, 16.5, 26.75)
ypos = -0.475
End If
Count = Count + 1
Next myStr
End Sub

p45cal
12-11-2012, 02:46 PM
So it depends what you want to do with blank values; leave blanks in the corresponding places in the coreldraw document? or just ignore them altogether? It's easy enough to test for a blank, at whatever stage.

loppydog
12-11-2012, 03:16 PM
Wow, This is great! That is a good question about the blanks. I suppose it makes most sense to just finish the script when it comes to the first blank. In other words... we may print 16 pcs, or we may print 48 pcs, but we will always start from the upper left corner (or number 1). We would never print say #32-48 for example. Hope this makes sense ;). Ignoring them should also work good as well, now that I think about it.

One more request if you would be so kind. Is there more options for things like line thickness and fill options? If so that would make this even more powerful for me! **edit** I just realized I can set my font default in Coreldraw to take care of this!

BTW...I assume you had no problem opening the most recent file?

also, where would be a good starting point for me to learn some of this stuff. I tried using the help, but I cannot find things in there related to fonts for instance. Like, where would I find a list of all the variables.

loppydog
12-12-2012, 12:59 PM
Hey p45cal, thanks again for the script, its working great for me(except the error for blank cells, but that's no big deal). I was wondering if you would take a look at one more thing for me. If I have "worn out my welcome" so to speak, you can tell me :).

The one last thing I need to see if I can accomplish is to import the data from the excel cells to a barcode. I have found a program that will allow creation of barcodes and it can be run via a VBA script. Here is a link:

h**p://strokescribe.com/en/create-barcode-coreldraw-vba.html

obviously this code is for inputting a string of text one at a time, but I am wondering if it could be tweaked to use the excel data. It would be similar to the other script as far as centered at the same location.

I know this is wondering very far off topic, and if I need to start a new topic I can. Thanks!:beerchug:

p45cal
12-12-2012, 01:00 PM
Ignoring them (blanks) should also work good as well, now that I think about it.Addressed below.
One more request if you would be so kind. Is there more options for things like line thickness and fill options? If so that would make this even more powerful for me!Also addressed below.
BTW...I assume you had no problem opening the most recent file?You assume correctly.
where would be a good starting point for me to learn some of this stuff. I tried using the help, but I cannot find things in there related to fonts for instance. Like, where would I find a list of all the variables.A very good start is to record yourself doing things in Corel and then looking at the resultant code. The recorder doesn't record everything however! The object browser (F2 in the vbe) should be fairly comprehensive - search for likely terms. Otherwise, perhaps look for books on Amazon?
Anyway, the updated code (still no added sophistication regarding the file handling):Sub blah1()
Dim EXCELAPP As Object
Set EXCELAPP = CreateObject("excel.application")
EXCELAPP.Visible = True

Set ExcelWkBk = EXCELAPP.Workbooks.Open(ActiveDocument.FilePath & "DataBase.xls")
With ExcelWkBk.sheets("Sheet1")
x = .Range(.cells(2, 1), .cells(2, 1).End(-4121))
End With
ExcelWkBk.Close SaveChanges:=False
EXCELAPP.Quit

ActiveDocument.ReferencePoint = cdrCenter
ypos = -0.475
xpos = 5.75
Count = 1
For Each myStr In x
If myStr <> "" Then
Set zz = ActiveLayer.CreateArtisticText(Left:=0, Bottom:=0, Text:=myStr, Font:="Arial", Size:=16)
zz.Fill.UniformColor.CMYKAssign 11, 69, 93, 0
zz.Outline.Width = 0.0032
zz.Outline.Color = CreateCMYKColor(11, 69, 93, 0)
zz.SetPosition xpos, ypos
ypos = ypos - 0.55
If (Count) Mod 32 = 0 Then
xpos = Choose(Count / 32, 16.5, 26.75)
ypos = -0.475
End If
Count = Count + 1
End If
Next myStr
End Sub

loppydog
12-12-2012, 02:07 PM
Thanks for the tips. Just test the code and it works perfectly! I used to have to input all this data manually, so you have really saved me some serious time:bow:. I am not sure if you noticed my post above since we posted at about the same time.

loppydog
12-13-2012, 12:20 PM
I actually think I figured this one out on my own! I just took your code and tweaked it a bit. Here is what I came up with:

Sub Import_QR_From_Excel()
Dim EXCELAPP As Object
Set EXCELAPP = CreateObject("excel.application")
EXCELAPP.Visible = True

Set ExcelWkBk = EXCELAPP.Workbooks.Open(ActiveDocument.FilePath & "DataBase.xlsx")
With ExcelWkBk.sheets("Sheet1")
x = .Range(.cells(2, 1), .cells(2, 1).End(-4121))
End With
ExcelWkBk.Close SaveChanges:=False
EXCELAPP.Quit


Dim sh As Shape
Dim ss As StrokeScribe

ActiveDocument.ReferencePoint = cdrCenter
ypos = -0.475
xpos = 5.75
Count = 1
For Each myStr In x
If myStr <> "" Then
Set sh = Application.ActiveLayer.CreateOLEObject("STROKESCRIBE.StrokeScribeCtrl.1")
Set ss = sh.OLE
ss.Text = myStr
ActiveDocument.Unit = cdrInch
sh.SizeHeight = 0.2
sh.SizeWidth = 0.4
ss.Alphabet = QRCODE
sh.SetPosition xpos, ypos
ypos = ypos - 0.55
If (Count) Mod 32 = 0 Then
xpos = Choose(Count / 32, 16.5, 26.75)
ypos = -0.475
End If
Count = Count + 1
End If
Next myStr
End Sub

p45cal
12-13-2012, 01:51 PM
That's the way to do it!
I don't have StokeScribe, si it would have been awkward to test (I know, it's free for non-commercial use, but I'd need to install it).
The only comment I'd make is regarding the line
ActiveDocument.Unit = cdrInch
which is being executed every time round the loop, I think it needs only to be executed once, so put it before and outside the loop perhaps next to the similar
ActiveDocument.ReferencePoint = cdrCenter


When I get some time I'll add something regarding better filehandling.

loppydog
12-13-2012, 02:09 PM
OK, I'll make that change. I think I can actually omit that reference.

I still don't understand most of the more complicated code, like the count reference and how myStr works. But I will keep researching a learning. I am not sure if StrokeScribe is my best option in this case, but it seems to work well. Thanks again for all your help, you have really been a lifesaver!

abu justice
01-30-2014, 12:43 AM
Now open the Excel file that is located in the same folder as this CorelDraw fie.
Workbooks.Open (ActiveDocument.FilePath & EXCEL_DATA_FILE)

getting compile error on workbooks
please help

p45cal
01-30-2014, 02:06 AM
1. Confirm you are running START in msg#5 (not jusr running GET_DATA by itself).
2. You are entering the name of the file correctly, including the .xls/.xlsx/.xlsm extension.
3. The Excel file is in the same folder as the Corel file.