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
 

Some videos you may like

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

ranman256

Well-known Member
Joined
Jun 17, 2014
Messages
1,971
you didn't say WHAT variable.

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

Watch MrExcel Video

Forum statistics

Threads
1,128,163
Messages
5,629,060
Members
416,363
Latest member
zaveedd

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
Top