Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default problem opening file thru code

I use the following code to open a file when a button on a userform is clicked:

'open template

Dim fn As String
Dim loc As String
Dim str As String

loc = Range("loc_template").Value
fn = Range("template").Value

On Error GoTo 200

str = loc & "\" & fn
Call OpenFile(str)

On Error GoTo 0

Unload Me

Exit Sub

200
MsgBox "Could not find " & str

End Sub

The code usually works fine; my problem is when I have modified and saved the "template"; which I do quite often. After the file has been saved and renamed, it will no longer open through the code. I adjust the range (range("template").value) to reflect the new name, but when I try to open it, the screen turns white and I have to restart. I know it is identifying the file, as it shows in the Task Manager as an application (actually two applications) but they are "not responding" and my code does not trip the file not found error; it finds the file, it just can't open it.

If I open the file manually, save, and close it with the same new name, it will then open through the code. I can't figure out what keeps it from opening after it has been modified. It is not really a template file, but, it is a .xlsm file that I use as a template, and it has a lot going on it; including database connections to a historical data source. Those connections are made through code, and are always closed at the end of the code. It does not appear to have any connections open, and when I open it and close it manually, I do not need to do anything to the file to get it to once again be re-openable through the code.

Any ideas?

Thanks

Ken
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default problem opening file thru code

Hi

The code for your OpenFile sub might help answer your query.

Pascal Baro
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default problem opening file thru code

Pascal

It doesn't say much, probably should just be another line in the listbox code I already posted.


Sub OpenFile(s)
Workbooks.Open Filename:=s
End Sub

Ken

On Saturday, November 24, 2012 6:06:32 PM UTC-5, pascal baro wrote:
Hi



The code for your OpenFile sub might help answer your query.



Pascal Baro


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
Problem opening an Excel file from code Christer Excel Programming 2 March 31st 10 05:31 PM
Problem in opening Excel which is already opened by VB code Naveen J V[_2_] Excel Programming 1 September 11th 08 04:28 PM
Add Code to File Opening Q Sean Excel Programming 7 July 14th 07 08:07 PM
Problem opening a file AmyTaylor[_22_] Excel Programming 4 August 16th 05 12:36 PM
opening file problem please help Steve Goodrich Excel Discussion (Misc queries) 2 March 1st 05 10:40 PM


All times are GMT +1. The time now is 02:29 PM.

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"