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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using "GetObject" to activate an Open Excel Workbook 1

Status
Not open for further replies.

ActMod

Technical User
Aug 25, 2003
45
US
Can anyone suggest why the following keeps giving me a "Type Mismatch" and how I might revise it to activate the Excel file named "MyExcel"?

Set objExcel = GetObject("C:\Documents and Settings\Access Practice File\MyExcel.xls")

Thank you for any help.

P.S. I am also looking for a way to open a dialog box that enables a User to browse my "C" Drive for a specific Excel file.
 
Just instantiate Excel and use its built-in capabilites:
Code:
Public Sub OpenExcel()
On Error Resume Next

  Dim xl As Excel.Application
  Dim wb As Excel.Workbook
  Dim sht As Excel.Worksheet
  
  Set xl = New Excel.Application    'instantiate Excel
  
  xl.Visible = True
  
  ' use Excel's built-in open dialog
  
  xl.Dialogs(xlDialogOpen).Show "C:\*.xls"
  Set wb = xl.ActiveWorkbook
  
  ' put appropriate sheet name/index here.
  
  Set sht = wb.Sheets(1)
  
  ' tinker with range properties
  
  With sht
    With .Range("E20", "G20")
      .Merge
      .Value = "Merged Cells"
      .HorizontalAlignment = xlHAlignCenter
      .Font = "Comic Sans"
      .Font.Size = 18
      .Font.Bold = True
      .Interior.ColorIndex = 27
    End With
    .Activate
  End With
  
  ' do more stuff...
  
End Sub


VBSlammer
redinvader3walking.gif

[sleeping]Unemployed in Houston, Texas
 
Thanks much VBSlammer. This worked great!!
Jim (ActMod)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top