Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Publisher / Programming / February 2008

Tip: Looking for answers? Try searching our database.

Import data to publisher from excel.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
hatcyl - 13 Jan 2008 07:40 GMT
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:)
Ed Bennett - 13 Jan 2008 12:17 GMT
> 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...
[quoted text clipped - 6 lines]
> 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?

Signature

Ed Bennett - MVP Microsoft Publisher
http://ed.mvps.org

hatcyl - 14 Jan 2008 03:49 GMT
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.

> > 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...
[quoted text clipped - 9 lines]
> How familiar are you with programming in general, and with programming
> in VBA in particular?
Ed Bennett - 14 Jan 2008 12:53 GMT
> 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.

Signature

Ed Bennett - MVP Microsoft Publisher
http://ed.mvps.org

hatcyl - 08 Feb 2008 05:42 GMT
Thank You. Sorry for the VERY late thanks, I didn't realize I had a response.

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.