Import data to publisher from excel.

H

hatcyl

Hello, I am using Office 2007. I have a little project I am trying to
accomplish.
I would like to make a PUBLISHER file than will read cells from an EXCEL
sheet and use those values to make a rectangle. Heres an example...
A B
2 128×96 4:03
3 176×120 22:15
4 176×144 11:09

thats the excel sheet. I want publisher to take A2, make it into a
rectangle. If possible color that rectangle depending on B2 (if B2=='4:03'
color='blue' or something.)

Any help? Thanks:)
 
E

Ed Bennett

hatcyl said:
I would like to make a PUBLISHER file than will read cells from an EXCEL
sheet and use those values to make a rectangle. Heres an example...
A B
2 128×96 4:03
3 176×120 22:15
4 176×144 11:09

thats the excel sheet. I want publisher to take A2, make it into a
rectangle. If possible color that rectangle depending on B2 (if B2=='4:03'
color='blue' or something.)

How familiar are you with programming in general, and with programming
in VBA in particular?
 
H

hatcyl

Hello, in pogramming I am fairly litarate. I know I would have to take the
dimensions and parse it into two (x being the dividing character) then I
would assign the height and width depending on those two parts. I have mostly
worked in Java.

In VBA I have 0 experience.

Thanks.
 
E

Ed Bennett

hatcyl said:
I have mostly
worked in Java.

In VBA I have 0 experience.

That makes my life easier. The main thing to note in VBA is that = means
both assignment and comparison, there is no ==.

Set a reference to the Excel object library in Tools > References.

Create an instance of the Excel application object

Dim eApp As New Excel.Application

Create a workbook object

Dim wBook As Excel.Workbook

Use Excel.Application.Workbooks.Open to open your Excel sheet, and use
wBook to reference this sheet

Set wBook = eApp.Workbooks.Open(arguments)

Then get the worksheet from this workbook

Dim wSheet as Excel.WorkSheet
Set wSheet = wBook.Sheets(index)

Use the .Cells(x,y) property of wSheet to get your cells.

VBA has no regex facilities, so you'll have to use InStr to find the
location of the x, then Left$ and Right$ to get the two numbers out.

Dim aShape As Publisher.Shape
Set aShape = ThisDocument.ActiveView.ActivePage.Shapes.Add(args)

will create you a shape. Properties are assigned as (for example)

aShape.Fill.ForeColor.RGB = RGB(0, 0, 255)

(to set the shape's fill to blue).

VBA's version of the switch statement is the Select Case, which goes:

Select Case i
Case 1
'do stuff
Case 2
'do other stuff
Case Else
'do non-handled case
End Select

(There is no "break".)

Similarly, the if statement:

If i Then
'do something
ElseIf j Then
'do something else
Else
'another thing
End If

The for statement:

For i = 1 to 5
MsgBox i
Next

(Note that function arguments must be enclosed in brackets if the return
value is being assigned to something, and must not be enclosed in
brackets otherwise; MsgBox in this case is the latter, hence no brackets.)

For collections, you can use For Each

Dim a As Publisher.Page
For Each a In ThisDocument.Pages
a.Shapes.AddPicture(...)
Next

Then do loops:

Do
'stuff
Loop While a < 4

Do While a < 4
'stuff
Loop

(See http://www.ozgrid.com/VBA/do-until-loop.htm)

If you're doing lots of stuff on a variable, use With

Dim a As Publisher.Pafe
Set a = ThisDocument.Pages(1)
With a
.Shapes.AddPicture(...)
End With

Loops can be broken out of prematurely with Exit [For|Do]; this also
applies for Subs with Exit Sub,

Comments are limited to single lines; everything after a ' is considered
a comment.

Any more questions, ask.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top