Combining Codes

wadiok

New Member
Joined
Jun 13, 2010
Messages
20
Do I use a command button or how what can I use to execute all these codes I place them in different modules without sucession? :ROFLMAO:

Code:
Private Const NO_ERROR = 0
Private Const ERROR_NOT_CONNECTED = 2250&
Private Const ERROR_MORE_DATA = 234
Private Const ERROR_NO_NETWORK = 1222&
Private Const ERROR_EXTENDED_ERROR = 1208&
Private Const ERROR_NO_NET_BAD_PATH = 1203&
 
Function WinUsername() As String
Dim strBuf As String, IngUser As Long, strUn As String
strBuf = Space$(255)
IngUser = WNetGetUSer("", strBuf, 255)
If IngUser = NO_ERROR Then
strUn = Left(strBuf, InStr(strBuf, vbNullChar) - 1)
WinUsename = strUn
Else
WinUsername = "error:" & IngUser
End If
End Function
 
Sub CheckUserRights()
Dim UserName As String
UserName = WinUsername
Select Case UserName
Case "Adminstrator"
MsgBox "Full Rights"
Case "Guest"
MsgBox "You Cannot Make Changes"
Case Else
MsgBox "Limited Rights:"
End Select
End Sub

Code:
'Show date and time when last saved
 
Function LastSaved(FullPath As String) As Date
LastSaved = FileDateTime(FullPath)
End Function
 
Function DateTime()
DateTime = Now
End Function

Code:
'Workbook Name
 
Function MyFullName() As String
MyFullName = ThisWorkbook.FullName
End Function
 
Last edited by a moderator:

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Not really sure what you are asking here.

I only see one Sub Procedure, and the rest are Functions. The only one you would call with a Command Button is your Sub Procedure. Functions are called from within Sub Procedures, or referenced directly on your worksheet like native Excel functions.
 
Upvote 0
Copy and paste into the same module. One after another. You'll see clear breaks for them with the Sub ___()

at the end of a code, simply use the call function
Code:
sub a()
...
Call b
end sub

sub b()
...
Call c
End sub
Sub c()
...
End sub

that or once you do that, change everything to private subs and create a simple consolidated Macro
Code:
Sub Consolidated_Macro()
Call Macro1
Call Macro2
if cells("B50") > 0 then call Macro 4
etc.
etc.

This would essentially loop through all macros and also allow you to make decision based events, such as the if statement to see if you want/need a macro to run.

jc
 
Upvote 0
woops, did not realize that you only have 1 sub and you created 2 functions...

Sorry, I'm with the other poster, I don't understand what you are trying to accomplish now...

jc
 
Upvote 0

Forum statistics

Threads
1,216,069
Messages
6,128,602
Members
449,460
Latest member
jgharbawi

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