VBA help

Franchise1375

New Member
Joined
May 19, 2020
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
Hi. I am very new to vba and need assistance. I am trying to pass a variable from the module to the userform. Can anyone advise? Thank you!

MODULE CODE:

Sub Input_file_path()

nxt:
file_path = InputBox("Enter filepath directory of output files", "")

If file_path = "" Then
'MsgBox "No data was entered, please retry."
'GoTo nxt:
GoTo ext:
Else
Debug.Print file_path

End If

msgbox (file_path)

Exit Sub
ext:
msgbox "You didn't enter anything."
msgbox "Ctrl Break here if you want to exit program."
End Sub


Public month_year As String
Public file_path As String

Sub CommandButton1_Click()
'Worksheets(ListBox1.Value).PrintOut



pdfName = ActiveSheet.Name
ChDir ActiveWorkbook.Path & "\"
fileSaveName = ActiveSheet.Name & month_year

msgbox (fileSaveName)


ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
fileSaveName _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True



USERFORM CODE:

Public month_year As String
Public file_path As String

Sub CommandButton1_Click()
'Worksheets(ListBox1.Value).PrintOut

pdfName = ActiveSheet.Name
ChDir ActiveWorkbook.Path & "\"
fileSaveName = ActiveSheet.Name & month_year

msgbox (fileSaveName)


ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
fileSaveName _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True


End Sub

Sub CommandButton_Click()

End Sub

Sub UserForm_Click()

End Sub

Sub UserForm_Initialize()
Dim n As Integer
Do
n = n + 1
ListBox1.AddItem Sheets(n).Name
Loop Until n = Worksheets.Count
End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
you didn't say WHAT variable.

but if
you can declare fileSaveName public so its available everywhere:
IN MODULE:
public fileSaveName as string
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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