ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Open file from a form (https://www.excelbanter.com/excel-programming/378491-open-file-form.html)

sonu[_2_]

Open file from a form
 
Private Sub TB_ImportIntoBook_Enter()
'MsgBox "This is enter"

Openwkb = Application.GetOpenFilename("FileToImportInto, *.xls")

Workbooks.Open (Openwkb)

TB_ImportIntoBook.Value = Openwkb

End Sub

I have the above code in a form. This code is in a text box and runs
when users enter in the text box. I can not open excel fie. If I
comment out the like "Workbooks.Open (Openwkb)" the form work fine but
also does not open the file. I want the file to open also then user
selects the file.

Can anyone help me with this. Is this possible or I am trying to do
something that is not possible.

Please let me know

Regards

Sonu.


sonu[_2_]

Open file from a form
 
And yes I want to keep the form open. If I unload the form I can open
the file but I need to keep the form open as well.

sonu wrote:
Private Sub TB_ImportIntoBook_Enter()
'MsgBox "This is enter"

Openwkb = Application.GetOpenFilename("FileToImportInto, *.xls")

Workbooks.Open (Openwkb)

TB_ImportIntoBook.Value = Openwkb

End Sub

I have the above code in a form. This code is in a text box and runs
when users enter in the text box. I can not open excel fie. If I
comment out the like "Workbooks.Open (Openwkb)" the form work fine but
also does not open the file. I want the file to open also then user
selects the file.

Can anyone help me with this. Is this possible or I am trying to do
something that is not possible.

Please let me know

Regards

Sonu.



Chip Pearson

Open file from a form
 
Your code works for me. Have you tried setting a Breakpoint on the
GetOpenFilename line and stepping through the code?


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)


"sonu" wrote in message
ps.com...
Private Sub TB_ImportIntoBook_Enter()
'MsgBox "This is enter"

Openwkb = Application.GetOpenFilename("FileToImportInto, *.xls")

Workbooks.Open (Openwkb)

TB_ImportIntoBook.Value = Openwkb

End Sub

I have the above code in a form. This code is in a text box and runs
when users enter in the text box. I can not open excel fie. If I
comment out the like "Workbooks.Open (Openwkb)" the form work fine but
also does not open the file. I want the file to open also then user
selects the file.

Can anyone help me with this. Is this possible or I am trying to do
something that is not possible.

Please let me know

Regards

Sonu.




sonu[_2_]

Open file from a form
 
Yes I did. When I set breakpoint it does not stop on it. I have to
check it with msgboxes. I have excel 2000. Did you try it in later
version.

Chip Pearson wrote:
Your code works for me. Have you tried setting a Breakpoint on the
GetOpenFilename line and stepping through the code?


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)


"sonu" wrote in message
ps.com...
Private Sub TB_ImportIntoBook_Enter()
'MsgBox "This is enter"

Openwkb = Application.GetOpenFilename("FileToImportInto, *.xls")

Workbooks.Open (Openwkb)

TB_ImportIntoBook.Value = Openwkb

End Sub

I have the above code in a form. This code is in a text box and runs
when users enter in the text box. I can not open excel fie. If I
comment out the like "Workbooks.Open (Openwkb)" the form work fine but
also does not open the file. I want the file to open also then user
selects the file.

Can anyone help me with this. Is this possible or I am trying to do
something that is not possible.

Please let me know

Regards

Sonu.



Chip Pearson

Open file from a form
 
I initially tried it in 2003 and it was successful. I then tried it in 2000
and it ran successfully. I'm surprised that the breakpoints didn't pause the
code. Put a Stop statement before the GetOpenFilename line. This will cause
VBA to stop on that line. Another method is to use Debug.Assert:

Debug.Assert False

The VBA code will pause execution on the Assert statement.

Once VBA is paused on the Stop or Assert statement, use F8 to step through
the code. If you have an "On Error Resume Next" in the code. remove it. You
want On Error Goto 0 to be in effect.



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)



"sonu" wrote in message
ups.com...
Yes I did. When I set breakpoint it does not stop on it. I have to
check it with msgboxes. I have excel 2000. Did you try it in later
version.

Chip Pearson wrote:
Your code works for me. Have you tried setting a Breakpoint on the
GetOpenFilename line and stepping through the code?


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)


"sonu" wrote in message
ps.com...
Private Sub TB_ImportIntoBook_Enter()
'MsgBox "This is enter"

Openwkb = Application.GetOpenFilename("FileToImportInto, *.xls")

Workbooks.Open (Openwkb)

TB_ImportIntoBook.Value = Openwkb

End Sub

I have the above code in a form. This code is in a text box and runs
when users enter in the text box. I can not open excel fie. If I
comment out the like "Workbooks.Open (Openwkb)" the form work fine but
also does not open the file. I want the file to open also then user
selects the file.

Can anyone help me with this. Is this possible or I am trying to do
something that is not possible.

Please let me know

Regards

Sonu.





sonu[_2_]

Open file from a form
 
Chip,

Thanks. I got it actually I also had another control on the same fom. I
have a RefEdit box on the same form. The problem is caused by that.
Once I deleted this control box the code works fine.

I am ok for now.

Thanks for all the help. I really appreciate it.

Sonu.


Chip Pearson wrote:
I initially tried it in 2003 and it was successful. I then tried it in 2000
and it ran successfully. I'm surprised that the breakpoints didn't pause the
code. Put a Stop statement before the GetOpenFilename line. This will cause
VBA to stop on that line. Another method is to use Debug.Assert:

Debug.Assert False

The VBA code will pause execution on the Assert statement.

Once VBA is paused on the Stop or Assert statement, use F8 to step through
the code. If you have an "On Error Resume Next" in the code. remove it. You
want On Error Goto 0 to be in effect.



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)



"sonu" wrote in message
ups.com...
Yes I did. When I set breakpoint it does not stop on it. I have to
check it with msgboxes. I have excel 2000. Did you try it in later
version.

Chip Pearson wrote:
Your code works for me. Have you tried setting a Breakpoint on the
GetOpenFilename line and stepping through the code?


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)


"sonu" wrote in message
ps.com...
Private Sub TB_ImportIntoBook_Enter()
'MsgBox "This is enter"

Openwkb = Application.GetOpenFilename("FileToImportInto, *.xls")

Workbooks.Open (Openwkb)

TB_ImportIntoBook.Value = Openwkb

End Sub

I have the above code in a form. This code is in a text box and runs
when users enter in the text box. I can not open excel fie. If I
comment out the like "Workbooks.Open (Openwkb)" the form work fine but
also does not open the file. I want the file to open also then user
selects the file.

Can anyone help me with this. Is this possible or I am trying to do
something that is not possible.

Please let me know

Regards

Sonu.





All times are GMT +1. The time now is 08:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com