If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
excel files
how do i set up an excel file to read spread sheets
|
#2
|
|||
|
|||
excel files
Do you mean to use automation to manipulate spreadsheets as opposed to
importing them using TransferSpreadsheet? If so, this code contains what you need to open a spreadsheet. That is done in the GetExcel Sub. If you want to create a new spreadsheet, read up on the CreateObject method in VBA Help. Paste this code into a standard module. Mine is named modExcelRoutines. I really don't use the GetExcel sub, but it is a good basis for learning how to open a spreadsheet. Also, to manipulate an Excel object, you will need to study up on the Excel Object model. I have found using the Object Browser in VBA is a great way to do that. Option Compare Database Option Explicit ' 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("c:\vb4\MYTEST.XLS") ' 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("XLMAIN", 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 "pattsy" wrote: how do i set up an excel file to read spread sheets |
#3
|
|||
|
|||
excel files
I'd suggest asking in a newsgroup related to Excel.
This newsgroup is for questions about Access, the database product that's part of Office Professional. -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no private e-mails, please) "pattsy" wrote in message ... how do i set up an excel file to read spread sheets |
#4
|
|||
|
|||
excel files
"pattsy" wrote: how do i set up an excel file to read spread sheets thanks for the help |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Excel Crash - Help! | Delbert | General Discussion | 13 | December 13th, 2005 10:02 PM |
unhide menu bar in excel - just disappeared | Sean | Setting up and Configuration | 11 | December 4th, 2005 08:01 PM |
suggestion for excel tool option | David Coleman | General Discussions | 7 | November 10th, 2005 03:33 AM |
Combining difficult Excel files | hamed_gan | General Discussion | 1 | November 8th, 2004 11:40 AM |
Coverting Lotus 123 files to use with excel | Muffin1947 | General Discussion | 6 | June 20th, 2004 10:18 AM |