Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Report to excel format - can this be done

Status
Not open for further replies.

Tapp

Vendor
Jan 15, 2003
15
0
0
US
HI
I wonder if this can be done I hope so but I tried and tried without any joy

the code is behind a button that outputs a report to excel what I want to do is squeeze a bit of code in that will change the excel page setup page to landscape

here it is

Private Sub Command5_Click()
On Error GoTo Err_Command5_Click

Dim stDocName As String

DoCmd.OutputTo acReport, _

"tryitReport", acFormatXLS, "C:\Tryit.xls", 1

'HER IS THE BIT I WANT TO ADD'

With WorkBook.PageSetup

.Orientation = xlLandscape
End With

' I have chopped it cut it pasted it everywhere but as yet have not found the way it' will work

Exit_Command5_Click:

Exit Sub

Err_Command5_Click:

MsgBox Err.Description

Resume Exit_Command5_Click

End Sub
 
Hi Tapp,
This should help, or at least point in the right direction. I copied it from the Access helpfile - GetObject Example.

' Declare necessary API routines:
Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName as String, _
ByVal lpWindowName As Long) As Long

Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hWnd as Long,ByVal wMsg as Long, _
ByVal wParam as Long, _
ByVal lParam As Long) As Long

Sub GetExcel()
Dim MyXL As Object ' Variable to hold reference
' to Microsoft Excel.
Dim ExcelWasNotRunning As Boolean ' Flag for final release.

' Test to see if there is a copy of Microsoft Excel already running.
On Error Resume Next ' Defer error trapping.
' Getobject function called without the first argument returns a
' reference to an instance of the application. If the application isn't
' running, an error occurs.
Set MyXL = Getobject(, "Excel.Application")
If Err.Number <> 0 Then ExcelWasNotRunning = True
Err.Clear ' Clear Err object in case error occurred.

' Check for Microsoft Excel. If Microsoft Excel is running,
' enter it into the Running Object table.
DetectExcel

' Set the object variable to reference the file you want to see.
Set MyXL = Getobject(&quot;c:\vb4\MYTEST.XLS&quot;)

' Show Microsoft Excel through its Application property. Then
' show the actual window containing the file using the Windows
' collection of the MyXL object reference.
MyXL.Application.Visible = True
MyXL.Parent.Windows(1).Visible = True
Do manipulations of your file here.
' ...
' If this copy of Microsoft Excel was not running when you
' started, close it using the Application property's Quit method.
' Note that when you try to quit Microsoft Excel, the
' title bar blinks and a message is displayed asking if you
' want to save any loaded files.
If ExcelWasNotRunning = True Then
MyXL.Application.Quit
End IF

Set MyXL = Nothing ' Release reference to the
' application and spreadsheet.
End Sub

Sub DetectExcel()
' Procedure dectects a running Excel and registers it.
Const WM_USER = 1024
Dim hWnd As Long
' If Excel is running this API call returns its handle.
hWnd = FindWindow(&quot;XLMAIN&quot;, 0)
If hWnd = 0 Then ' 0 means Excel not running.
Exit Sub
Else
' Excel is running so use the SendMessage API
' function to enter it in the Running Object Table.
SendMessage hWnd, WM_USER + 18, 0, 0
End If
End Sub

 
Thank you very much Katerine

I am working with it but so far not much is happening

Trouble is Im just beginning to lear n access and I think my ideas surpas my skills by a lolng way but I'm keen willing to learn and best of all enjoying it


thanks again

:)
 
Hi Tapp,
And this is bad? The best way to learn Access is to have ideas that surpass your skills, and then study until you've figured out how to do it. Come to think of it, there really is no other way to learn Access, or any programming for that matter. The only key is to not give up. If you can conceive of it, odds are about 98% that it CAN be done! :) Katie
Hi! I'm currently studying the COM+ programming model. Hopefully YOU'RE having fun, which would make one of us..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top