ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Simple Form: How to copy a value from one object to another? (https://www.excelbanter.com/excel-programming/386047-simple-form-how-copy-value-one-object-another.html)

Dirk Diggler

Simple Form: How to copy a value from one object to another?
 
hello everyone,

There is a simple form in Excel: one button, and one textbox. The button
has a CommandButton1_Click() procedure defined as a call to the
following subroutine:

Public Sub ChooseUniverse()
Dim sFile As String

sFile = Application.GetOpenFilename(FileFilter:= _
"TXT Files (*.txt), *.txt", FilterIndex:=1, _
Title:="Choose TXT File...")
End Sub

I tried to figure out if it was possible to pass the sFile value to the
textbox so that after choosing a file its path would be visible in the
textbox, but I failed at looking for some understandable examples.

Does anybody know it is possible and how can be done? I would appreciate
any suggestions or hints, or a link to some tutorial (with Excel).

thank you,
DD

ps. Follow-Up To: microsoft.public.excel.programming

RB Smissaert

Simple Form: How to copy a value from one object to another?
 
Not I understand the problem.
How about simply Textbox1.Text = sFile

RBS


"Dirk Diggler" wrote in message
...
hello everyone,

There is a simple form in Excel: one button, and one textbox. The button
has a CommandButton1_Click() procedure defined as a call to the following
subroutine:

Public Sub ChooseUniverse()
Dim sFile As String

sFile = Application.GetOpenFilename(FileFilter:= _
"TXT Files (*.txt), *.txt", FilterIndex:=1, _
Title:="Choose TXT File...")
End Sub

I tried to figure out if it was possible to pass the sFile value to the
textbox so that after choosing a file its path would be visible in the
textbox, but I failed at looking for some understandable examples.

Does anybody know it is possible and how can be done? I would appreciate
any suggestions or hints, or a link to some tutorial (with Excel).

thank you,
DD

ps. Follow-Up To: microsoft.public.excel.programming



Bob Flanagan

Simple Form: How to copy a value from one object to another?
 
Dirk, you can do it like the following;

Private Sub CommandButton1_Click()
Dim sFile As String

sFile = Application.GetOpenFilename(FileFilter:= _
"TXT Files (*.txt), *.txt", FilterIndex:=1, _
Title:="Choose TXT File...")
If sFile < "False" Then
Me.TextBox1.Text = sFile
End If
End Sub

Bob Flanagan
Macro Systems
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel

"Dirk Diggler" wrote in message
...
hello everyone,

There is a simple form in Excel: one button, and one textbox. The button
has a CommandButton1_Click() procedure defined as a call to the following
subroutine:

Public Sub ChooseUniverse()
Dim sFile As String

sFile = Application.GetOpenFilename(FileFilter:= _
"TXT Files (*.txt), *.txt", FilterIndex:=1, _
Title:="Choose TXT File...")
End Sub

I tried to figure out if it was possible to pass the sFile value to the
textbox so that after choosing a file its path would be visible in the
textbox, but I failed at looking for some understandable examples.

Does anybody know it is possible and how can be done? I would appreciate
any suggestions or hints, or a link to some tutorial (with Excel).

thank you,
DD

ps. Follow-Up To: microsoft.public.excel.programming




Dave Peterson

Simple Form: How to copy a value from one object to another?
 
There are followups in .programming.

Dirk Diggler wrote:

hello everyone,

There is a simple form in Excel: one button, and one textbox. The button
has a CommandButton1_Click() procedure defined as a call to the
following subroutine:

Public Sub ChooseUniverse()
Dim sFile As String

sFile = Application.GetOpenFilename(FileFilter:= _
"TXT Files (*.txt), *.txt", FilterIndex:=1, _
Title:="Choose TXT File...")
End Sub

I tried to figure out if it was possible to pass the sFile value to the
textbox so that after choosing a file its path would be visible in the
textbox, but I failed at looking for some understandable examples.

Does anybody know it is possible and how can be done? I would appreciate
any suggestions or hints, or a link to some tutorial (with Excel).

thank you,
DD

ps. Follow-Up To: microsoft.public.excel.programming


--

Dave Peterson

Dirk Diggler

Simple Form: How to copy a value from one object to another?
 
thank you, guys! I tried to use Value property of TextBox1, and
mistakenly referenced the function.

thanks,
DD

Bob Flanagan wrote:
Dirk, you can do it like the following;

Private Sub CommandButton1_Click()
Dim sFile As String

sFile = Application.GetOpenFilename(FileFilter:= _
"TXT Files (*.txt), *.txt", FilterIndex:=1, _
Title:="Choose TXT File...")
If sFile < "False" Then
Me.TextBox1.Text = sFile
End If
End Sub


jan

Simple Form: How to copy a value from one object to another?
 
Dirk,

This could do the job for you.
The subroutine ChooseUniverse I changed in a Function.

Private Sub CommandButton1_Click()
Dim sFile As Variant
sFile = ChooseUniverse
If sFile < False Then
Me.TextBox1 = sFile
Else
Me.TextBox1 = Null
End If
End Sub

Public Function ChooseUniverse() As Variant
Dim sFile As String
sFile = Application.GetOpenFilename(FileFilter:= _
"TXT Files (*.txt), *.txt", FilterIndex:=1, _
Title:="Choose TXT File...")
ChooseUniverse = sFile
End Function

Jan




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

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