Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Open a file and execute code

My bet is that you have two procedures (in different modules) that have the same
name.

If I'm right, I'd go back and fix it.

BlairH wrote:

Thanks for your help on this Dave.

I seem to have it working. Apparently it wants you to specify the name of
the module. It works if the Run command looks like this:

application.run "'" & wkbk.name & "'!Module1.Test_code_exec"

Blair

"Dave Peterson" wrote:

I'm still guessing that you have a typo somewhere.

BlairH wrote:

Test_code_exec is in Module1 of NCR_db.xls and is defined as a Public Sub.

"Dave Peterson" wrote:

So your "test_code_exec" procedure is in that NCR_db.xls workbook?

If yes, I'd use:

Option Explicit
Private Sub Workbook_Open()
Dim Wkbk as workbook
dim LogFileName as string

'Set the name and location of the log file
LogFileName = "C:\NCR_db.xls"

set wkbk = nothing
on error resume next
set wkbk = Workbooks.Open(Filename:=LogFileName)
on error goto 0

'check to see if it opened ok
if wkbk is nothing then
msgbox logfilename & " didn't open!"
else
'me is the object that owns the code
me.activate
'run the code in the workbook that this code opened
application.run "'" & wkbk.name & "'!Test_code_exec"
end if

End Sub

(Untested, uncompiled. Watch for typos.)

BlairH wrote:

I'm trying to open a file and execute code in that file. Here's what I've got:

Private Sub Workbook_Open()

WName = ActiveWorkbook.Name
LogFileName = "C:\NCR_db.xls" ' Set the name and location of the
log file
Workbooks.Open Filename:=LogFileName ' open the log file
LFName = ActiveWorkbook.Name ' return the name of the workbook
Workbooks(WName).Activate

Call Test_code_exec ' pass control to
the main code

End Sub

I keep getting an undefined Sub or Function error. The file doesn't open so
it look slike the error occurs before the code exexcutes - VB is trying to
identify all of its calls before execution, and since this is in a different
file it doesn't recognize it.

The Declare statement allows you to identify external subroutines in DLLs,
but can you specify that the code is external in another VB Project / Excel
file?

This is in XL2003.

Thanks,

Blair

--

Dave Peterson
.


--

Dave Peterson
.


--

Dave Peterson
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
Open txt file using vba code tom Excel Programming 2 July 3rd 09 02:34 AM
Execute VB code against certain open workbooks JDaywalt Excel Programming 12 March 11th 08 09:26 PM
Execute code from book1 of code from book2 Rick Excel Programming 4 June 5th 07 05:19 PM
How to open a zip file from the code? ana Excel Programming 1 April 26th 04 02:49 PM
VBA code to open file? pgoodale[_2_] Excel Programming 4 December 30th 03 01:41 PM


All times are GMT +1. The time now is 01:45 AM.

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

About Us

"It's about Microsoft Excel"