Setting a variable to equal whats in a textbox

rstanton1

New Member
Joined
Jul 8, 2004
Messages
27
I have a User form that I primary use as criteria for a variety of queries, but now I need to export a file.

I currently use a texbox to tell the TransferSpreasheet method through a Macro what name to give the spreadsheet as it gets exported. I would like to now open the newly-created spreadsheet in Excel.

The problem is that the variable strFileName never captures the .text property.

Public Function OpenMacroFromExcel()
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook

Call GetFileName

Set xlApp = New Excel.Application

With xlApp
.Visible = True
Set xlWB = .Workbooks.Open(strfilename)
End With
Workbooks.Open
xlWB.Application.Run "Automate_Regression"

Set xlWB = Nothing
Set xlApp = Nothing

End Function

Sub GetFileName()
dim strFileName as String
strFileName = forms!test!txtfilename.text
End Sub

Can anyone assist me?
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
assuming that forms!test!txtfilename is an Access form you probably don't need the .text.


GetFileName() is a sub not a function so It wont return anything anyway.

To return a value from a function you need to refer back to its name
GetFileName = forms!test!txtfilename

and you can do this without the function in the first place


Set xlWB = .Workbooks.Open(forms!test!txtfilename)

Though I would probably put it into a variable first so that it could be checked for validity as a file name.

Peter
 
Upvote 0

Forum statistics

Threads
1,221,777
Messages
6,161,871
Members
451,727
Latest member
tyedye4

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top