PLease help with automating excel from access vba

RichardP1978

Registered User.
Local time
Today, 02:15
Joined
Nov 14, 2006
Messages
89
OK,

I have spent all morning trying to work this out to no avail.

This is some code I use,

Dim obj As Object

Set obj = GetObject("f:\clientdatabase\templates\ChartTemplates.xls")
obj.Application.Visible = True
obj.Windows(1).Visible = True
obj.Application.ScreenUpdating = True
obj.Application.Goto "TobaccoLogTitleBar"
obj.Application.ActiveCell = "Tobacco Log for " & Forms![frmclientmain]![FirstName] & " " & Forms![frmclientmain]![Surname]
obj.PrintOut

The problem I have got is that the print command prints the entire workbook out, I have tried various alternatives using the code from this link to provide inspiration, but I am fresh out. http://www.rondebruin.nl/print.htm#Print

I would like the code to insert the relevant data in to the cell (which it does) and then print the active worksheet, not the whole workbook which is what it is doing. I dont mind if I have to code it to print the worksheet by its name, or through some 'activesheet' style command. If it cant be done whereby you can single out a worksheet within a workbook, so be it, but I would prefer to have all my charts in one file to keep tracking them easier.

I would like it to close the book without saving changes and close excel, although I would imagine this would be very similar to the word option.

Hope you can help.
 
Right off the top of my head, I think you need to refer to the active worksheet (Obj.ActiveWorksheet.PrintOut), but of course I could be wrong
 
Just because Excel has to be clunky about it, it's "ActiveSheet", not ActiveWorksheet, but other than that, it's the correct track to go down.

To close without saving (even though you've made a change), you have to turn off DisplayAlerts, which is the equivalent of "SetWarnings False" in Access.

~Moniker
 
Thank you guys.
It is always so damn simple it is frustrating sometimes, works like a charm.

I prefer to use Excel for somethings as there is the option to fit to page on documents when doing forms etc so if someone had a field that is slightly larger than it normally would be, whereas word will probably get all screwed up.
 

Users who are viewing this thread

Back
Top Bottom