Open a .xls from Command button

paulcraigdainty

Registered User.
Local time
Today, 13:44
Joined
Sep 25, 2004
Messages
74
I want a specific Excel spreadsheet to open when users click on a command button. I have tried using docmd [spreadsheet path] but this doesn't seem to work.
 
Paul,

In future, please keep your question to one post. I've deleted your identical post.
 
Code:
Application.FollowHyperlink "C:\mysheet.xls"

Also, I'm sure you'd have got an answer faster if you'd searched the forum as this is a very popular question.
 
Code:
    Dim app As Object                       [COLOR=Green]'excel application[/COLOR]
    Dim file As Object                      [COLOR=Green]'excel file[/COLOR]
    Dim ws As Object                        [COLOR=Green]'worksheet[/COLOR]

    Set app = CreateObject("Excel.Application")                 [COLOR=Green]'This opens excel application windows[/COLOR]
 
    
    Set file = app.Workbooks.Open("C:\File Folder\File Name.xls")
    Set ws = file.Worksheets(1)                                 [COLOR=Green]'This opens your sheet that you want to write to[/COLOR]
  [COLOR=Green]'Set ws = file.Worksheets("Sheet Name") -- you could use this too[/COLOR]
    ws.Activate
    
    Sheets(1).Select (1)
  [COLOR=Green]'Sheets(1).Select -- could do it this way too[/COLOR]
    Rows("1:3").Select
    Selection.Delete Shift:=xlUp

The above opens up a file that you want... and a sheet of your choosing, then it selects the top three rows and deletes them. Take from it what you need.

-modest
 

Users who are viewing this thread

Back
Top Bottom