Call Macro

erutherford

Active Member
Joined
Dec 19, 2016
Messages
449
Not sure what is causing the issue here but I do know people here will spot in a second.
I have 3 modules that I call for in another module. The main module works fine calling two other modules, but not three! Each works fine separately, but when all 3 are called "error" occurs.

VBA Code:
Sub Openflashdrive()

Dim strFile As String
MsgBox "Select * regdwnld.xlsx * file next."
strFile = Application.GetOpenFilename(FileFilter:="Excel files, *.xlsx", Title:="Choose regdwnld file")
Workbooks.Open strFile

Call ReorderColumns
Call AutoFitColumns
Call HideColumns

End Sub
"HideColumns" causes the error "Sub or Function not defined". It works fine when run separately, but not will called. Here is the code for HideColumns
VBA Code:
Private Sub HideColumns() 'Hide Columns

Dim wb As Workbook
Dim ws As Worksheet

Set wb = Workbooks("regdwnld.xlsx")
Set ws = wb.Worksheets("export")

ws.Activate
    ws.Range("K:BT").EntireColumn.Hidden = True
End Sub

Thanks in advance!
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
It can't see Private subs. Make this change:

Rich (BB code):
Public Sub HideColumns() 'Hide Columns
 
Upvote 0
Solution
Told you! This group is the greatest. I'll do some homework on the diff between public and private so I know why. Thanks 6 stringer and happy rifs!
 
Upvote 0
The difference is very simple:

A Private element is not visible outside of the module is declared in
A Public element is visible in any module

The rules are a little more involved when you do not explicitly say Private or Public.
  • In a standard module (like Module1) if you do not specific Private or Public, a Function or Sub will default to Public.
  • In a worksheet module (like Sheet1) if you do not specific Private or Public, a Function or Sub will default to Public. Regardless of whether you specified Public or allowed it to default, outside a sheet module you must explicitly qualify it to call it. For example, if Sheet1 has a Sub declared as
    VBA Code:
    Sub Sheet1Public()
    then the calling statement in another module must be
    VBA Code:
    Sheet1.Sheet1Public
  • If you declare a variable with a Dim statement at the top of a module, it will default to Private. To make it Public, use Public instead of Dim.
  • If you declare a constant with a const statement at the top of a module, it will default to Private. To make it Public, use Public Const.
  • You cannot declare a constant as Public in a worksheet module.
There are probably other rules I am forgetting.
 
Upvote 0

Forum statistics

Threads
1,214,592
Messages
6,120,433
Members
448,961
Latest member
nzskater

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