Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default VBA open file from a form

I am trying to open a file from a userForm....When stepping through
the code; when it gets to the FileNm part where it sets the Files name
to open, it runs to the end. I am pretty sure this is not normal.
How do I get this back to where I can step through line by line with
F8? Code is below.

Thanks,
Jay

Private Sub Enter_Click()
Dim LastRow As Long
Dim FileNm As String
Dim Master As Workbook
ChDir "G:\Masters\"
LastRow = Range("A65536").End(xlUp).Row + 1

FileNm = Application.GetOpenFilename(Title:="Please choose a file
to import.", MultiSelect:=False)
Set Master = Workbooks.Open(Filename:=FileNm, ReadOnly:=True)
With Master.Sheets(1)


End With
Range("A" & LastRow).Value = Now

Unload Me
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,203
Default VBA open file from a form

Well, hard to say - a lot could be going on when you hit the Set Master =
statement.
You could put a Stop statement right after that one as:

Set Master = Workbooks.Open(Filename:=FileNm, ReadOnly:=True)
Stop
With Master.Sheets(1)

Or put a breakpoint at the With Master.Sheets(1) statement. To put a
breakpoint in, move your cursor to the left of the code line, into the gray
bar running down the left side of the code window and just click there. A
red dot will appear indicating the breakpoint (much the same as a Stop
instruction). To remove the breakpoint later, just click on it or use
Debug--Clear All Breakpoints ([Ctrl]+[Shift]+[F9]).


"jlclyde" wrote:

I am trying to open a file from a userForm....When stepping through
the code; when it gets to the FileNm part where it sets the Files name
to open, it runs to the end. I am pretty sure this is not normal.
How do I get this back to where I can step through line by line with
F8? Code is below.

Thanks,
Jay

Private Sub Enter_Click()
Dim LastRow As Long
Dim FileNm As String
Dim Master As Workbook
ChDir "G:\Masters\"
LastRow = Range("A65536").End(xlUp).Row + 1

FileNm = Application.GetOpenFilename(Title:="Please choose a file
to import.", MultiSelect:=False)
Set Master = Workbooks.Open(Filename:=FileNm, ReadOnly:=True)
With Master.Sheets(1)


End With
Range("A" & LastRow).Value = Now

Unload Me
End Sub
.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,203
Default VBA open file from a form

Also, remember that once you do open the Master book, it's going to become
the active workbook, and your
Range("A" & lastRow).Value=Now
statement is going to take affect on the active sheet in the Master workbook
unless you re-activate "ThisWorkbook" or specify the sheet in ThisWorkbook to
write that value to, as
ThisWorkbook.Activate
Range("A" & LastRow).Value = Now

or
ThisWorkbook.Worksheets("somesheetname").Range("A" & LastRow).Value = Now


"jlclyde" wrote:

I am trying to open a file from a userForm....When stepping through
the code; when it gets to the FileNm part where it sets the Files name
to open, it runs to the end. I am pretty sure this is not normal.
How do I get this back to where I can step through line by line with
F8? Code is below.

Thanks,
Jay

Private Sub Enter_Click()
Dim LastRow As Long
Dim FileNm As String
Dim Master As Workbook
ChDir "G:\Masters\"
LastRow = Range("A65536").End(xlUp).Row + 1

FileNm = Application.GetOpenFilename(Title:="Please choose a file
to import.", MultiSelect:=False)
Set Master = Workbooks.Open(Filename:=FileNm, ReadOnly:=True)
With Master.Sheets(1)


End With
Range("A" & LastRow).Value = Now

Unload Me
End Sub
.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default VBA open file from a form

On Apr 27, 2:03*pm, JLatham wrote:
Also, remember that once you do open the Master book, it's going to become
the active workbook, and your
Range("A" & lastRow).Value=Now
statement is going to take affect on the active sheet in the Master workbook
unless you re-activate "ThisWorkbook" or specify the sheet in ThisWorkbook to
write that value to, as
ThisWorkbook.Activate
Range("A" & LastRow).Value = Now

or
ThisWorkbook.Worksheets("somesheetname").Range("A" & LastRow).Value = Now



"jlclyde" wrote:
I am trying to open a file from a userForm....When stepping through
the code; when it gets to the FileNm part where it sets the Files name
to open, it runs to the end. *I am pretty sure this is not normal.
How do I get this back to where I can step through line by line with
F8? *Code is below.


Thanks,
Jay


Private Sub Enter_Click()
* * Dim LastRow As Long
* * Dim FileNm As String
* * Dim Master As Workbook
* * ChDir "G:\Masters\"
* * LastRow = Range("A65536").End(xlUp).Row + 1


* * FileNm = Application.GetOpenFilename(Title:="Please choose a file
to import.", MultiSelect:=False)
* * Set Master = Workbooks.Open(Filename:=FileNm, ReadOnly:=True)
* * With Master.Sheets(1)


* * End With
* * Range("A" & LastRow).Value = Now


* * Unload Me
End Sub
.- Hide quoted text -


- Show quoted text -


I fully inderstand what you are gettign at...I just have no idea why
it is doing this. It just started doing this today. I use to be bale
to step through line by line even when opening a workbook. Now for
some reason it just takes off and finishes the macro. I do not want
to have to set my whole code as breaks to step through it.

Thanks for trying,
Jay
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 Last Modified File form Location Kam Excel Discussion (Misc queries) 4 December 30th 09 05:47 PM
How can I open excel template form in a shared file using vista? paultrvrs Excel Discussion (Misc queries) 1 November 3rd 09 07:25 PM
Open Form when file opened Dana Excel Discussion (Misc queries) 2 July 25th 08 04:36 PM
Open Form Automatically in Excel File Bejewell New Users to Excel 1 November 16th 05 06:18 PM
Create a form to open a comma delimited file ~Rick Excel Discussion (Misc queries) 1 September 29th 05 08:25 PM


All times are GMT +1. The time now is 09:26 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"