Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
CAM CAM is offline
external usenet poster
 
Posts: 65
Default Run a macro from one excel file to another excel file

Hello,

I am using an Excel 2007 file containing several command buttons I call this
Excel file "AMProcessing". On one particular command button I want to run a
particular vba coding (marco) in the "AMProcessing" workbook that needs to
be used for another Excel file called "CCCardExpense". The vba coding will
do what it needs to do for "CCCardExpense" file. I don't want to put the
vba coding in the "CCCardExpense", because it is a download file "master".
How can I use one Excel file to run the vba coding (macro) for another
Excel file. I want to avoid puting a command button in the toolbar itself.
If I have to open "CCCardExpense" file that's fine, but I want to have it
close automaticlly after the macro is run. Any tips will be appreciated.
Thank you in advance.

Cheers,

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Run a macro from one excel file to another excel file

maybe something on the order of this as long as the files are in the same
folder. if not you need to change the location:

Sub test()
Dim ws As Worksheet
Dim ws2 As Worksheet
Dim wb As Workbook
Dim wb2 As Workbook
Dim fPath As String
Dim file2 As String
fPath = ThisWorkbook.Path & "\"
file2 = "CCCardExpense.xls"
Application.ScreenUpdating = False

Set ws = Worksheets("sheet1")
' test for CCCardExpense.xls
If Len(Dir(fPath & file2)) 0 Then
Set wb2 = Workbooks.Open(fPath & file2, ReadOnly:=True)
Set ws2 = wb2.Worksheets("Sheet1")
Else
MsgBox "CCCardExpense.xls not found."
Exit Sub
End If

With wb2
.Activate
'Run your code making sure to qualify workbook and ranges of
cccardexpense
ws.Range("A2").Value = ws2.Range("A10").Value ' example
End With

wb2.Close savechanges:=False
Application.ScreenUpdating = True
End Sub


--


Gary


"CAM" wrote in message
...
Hello,

I am using an Excel 2007 file containing several command buttons I call this
Excel file "AMProcessing". On one particular command button I want to run a
particular vba coding (marco) in the "AMProcessing" workbook that needs to be
used for another Excel file called "CCCardExpense". The vba coding will do
what it needs to do for "CCCardExpense" file. I don't want to put the vba
coding in the "CCCardExpense", because it is a download file "master". How can
I use one Excel file to run the vba coding (macro) for another Excel file.
I want to avoid puting a command button in the toolbar itself. If I have to
open "CCCardExpense" file that's fine, but I want to have it close
automaticlly after the macro is run. Any tips will be appreciated. Thank you
in advance.

Cheers,



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel '00, 1st file has macros, how to stop macro in 2nd file? kaptandrews Excel Discussion (Misc queries) 0 May 24th 06 03:07 PM
how can i call macro in powerpoint file from excel file pm[_2_] Excel Programming 3 January 6th 06 10:40 PM
Macro to save Excel file with date and time in the file name? sonic_d_hog Excel Programming 2 January 5th 06 05:57 PM
Creating a new excel file from an existing file using macro Macro Excel Programming 2 July 28th 05 06:40 PM
VBA Macro to copy an column from one Excel file into another file Sam Excel Programming 4 July 3rd 05 03:36 AM


All times are GMT +1. The time now is 10:30 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"