ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA question - calling Procedure from userform (https://www.excelbanter.com/excel-programming/295111-vba-question-calling-procedure-userform.html)

ajliaks[_3_]

VBA question - calling Procedure from userform
 
Hi!

This may be a fool question, but I need the right answer :)

I have these procedures in a userform called "Importing" wich gives m
the location of some file, with the route,name of file and sheet
need, like this:

Private Sub cmdSearchSource_Click()
Dim V As Variant
V = Application.GetOpenFilename("Excel files,*.xls", _
1, "Select source file", , False)
If (Left(V, 3) < "Fal") Then
FileLocate.Text = V
FileName.Text = Right(V, Len(V) - 71)
End If
End Sub

Private Sub SheetName_Change()
Dim Sheet As String
Sheet = SheetName
End Sub


and have an other in a module called "OpenSaveClose" like this:

Sub OpenFile()
Workbooks.Open (V)
'here sentence to copy "Sheet from opened workbook to the workbook I a
working in called "oldworkbook"

End Sub

So I need to call Sub OpenFile from userform "Importing"

Thanks

--
Message posted from http://www.ExcelForum.com


kkknie[_40_]

VBA question - calling Procedure from userform
 
Not sure if I've understood, but it sounds like you want to pass th
filename to the other subroutine. Here's how you would do that:

Sub OpenFile(xFilename)
Workbooks.Open (xFilename)
'here sentence to copy "Sheet from opened workbook to the workbook I a
working in called "oldworkbook"

End Sub

Then call it from the userform using

Call OpenFile(V)

(assuming v is your filename from your original post.



--
Message posted from http://www.ExcelForum.com


Bob Phillips[_6_]

VBA question - calling Procedure from userform
 
Make sure that OpenFile is a public sub in a standard code module.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"kkknie " wrote in message
...
Not sure if I've understood, but it sounds like you want to pass the
filename to the other subroutine. Here's how you would do that:

Sub OpenFile(xFilename)
Workbooks.Open (xFilename)
'here sentence to copy "Sheet from opened workbook to the workbook I am
working in called "oldworkbook"

End Sub

Then call it from the userform using

Call OpenFile(V)

(assuming v is your filename from your original post.

K


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 04:42 AM.

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