Website Upgrade Incoming - we're working on a new look (and speed!) standby while we deliver the project

Tips on using this forum..

(1) Explain your problem, don't simply post "This isn't working". What were you doing when you faced the problem? What have you tried to resolve - did you look for a solution using "Search" ? Has it happened just once or several times?

(2) It's also good to get feedback when a solution is found, return to the original post to explain how it was resolved so that more people can also use the results.

Custom Button

4 replies [Last post]
Hemanth Kumar
User offline. Last seen 1 year 33 weeks ago. Offline
Joined: 1 Nov 2002
Posts: 260
Groups: None
Dear All

I Want To Add A Custom Button In MSP2003
To Open An Excel File Which I Use Frequently

My File Path Is C:\Data\Attendance.xls

I Have Created Button , Can Anyone List The Code To Assign It

I Tried To Record Macro And Assign It , But no success


thanks

hemant

Replies

Brian Ultican
User offline. Last seen 17 years 34 weeks ago. Offline
Joined: 10 Jun 2007
Posts: 24
Groups: None
I dont know what to say. It worked fine for me on two different machines.
Hemanth Kumar
User offline. Last seen 1 year 33 weeks ago. Offline
Joined: 1 Nov 2002
Posts: 260
Groups: None
Unfortunately Your Code Does Not Works

Here is the working way

Create a custom button

Press Alt F11
select "this project"
insert "new Module’
in that module

Cut and paste the following code
----------------------------------------------------------------

Const SW_SHOW = 1
Const SW_SHOWMAXIMIZED = 3

Public Declare Function ShellExecute Lib "Shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long

Sub RunYourProgram()
Dim RetVal As Long
On Error Resume Next
RetVal = ShellExecute(0, "open", "C:\Documents and Settings\planner\My Documents\0Essentials\GRAFICS for MSP.xls", "", _
"C:\MASTER", SW_SHOWMAXIMIZED)
End Sub
------------------------------------------------------------------------------------------------------------------------

were "C:\MASTER" MASTER is a blank folder in my computer

and "GRAFICS for MSP.xls" is the file to be opened

Rename the module , should not be like module1, etc give any name
now save this module to GLOBAL.mpt

now -assign "RunYourProgram" macro to the button

it works
Code Courtsey ::::::: michael@suodenjoki.dk

Thanks
hemant






Hemanth Kumar
User offline. Last seen 1 year 33 weeks ago. Offline
Joined: 1 Nov 2002
Posts: 260
Groups: None
Thanks

I l ll have a try
Brian Ultican
User offline. Last seen 17 years 34 weeks ago. Offline
Joined: 10 Jun 2007
Posts: 24
Groups: None
Assign the VBA macro below to a new button

Sub OpenAttendance()
Dim xlapp As Object

Set xlapp = CreateObject("excel.Application")
xlapp.Workbooks.Open FileName:="C:\Data\Attendance.xls"

xlapp.Visible = True


End Sub