OssieMac
2/3/2010 3:06:00 AM
Hi Brian,
Variables simply declared at the top of the module before any other subs but
still declared as Dim can all be used in any sub within that same module.
If you want to use the variables in other modules then declare them at the
top of a standard module but use Public.
Examples
Dim myVariable 'Can use in any sub in same module
Public myPublicVariable 'Can be used in any module
--
Regards,
OssieMac
"Brian" wrote:
> Did I do it correctly by moving all my declaration up to the top, instead of
> having them in each sub?
>
> "OssieMac" wrote:
>
> > Hi Brian,
> >
> > When the code is in the Userform module, the system knows that the controls
> > belong to the userform by default. when you move it out of the userform
> > module, you have to tell the syetem where the controls are.
> >
> > Looking at your code the following appear to be references to controls on
> > the userform.
> > CLLI_Code_1.Value
> > TEO_No_1.Value
> > CES_No_1.Value
> > TEO_Appx_No_2.Value
> >
> > You need to prefix them with the userform name and a dot like the following.
> >
> > Userform1.CLLI_Code_1.Value
> >
> > --
> > Regards,
> >
> > OssieMac
> >
> >
> > "Brian" wrote:
> >
> > > This code worked perfect when it was in the User Form Code Window, but I
> > > moved it to a module and I get a Run Time Error "424' Object Required
> > >
> > > Code in the User Form Window
> > > --------------------------------------------------
> > > '*******************************************************
> > > 'Save Installer Forms 11 Control Button
> > > 'Located in M3_Save_Workbook
> > > '*******************************************************
> > >
> > > Private Sub Save_Installer_Forms_11_Click()
> > >
> > > Call Save_Installer_Forms
> > >
> > > End Sub
> > >
> > >
> > > Code Located in the module:
> > >
> > > Declarations
> > > ----------------------------------------
> > > Dim strFile As String
> > > Dim fileSaveName As Variant
> > > Dim myMsg As String
> > >
> > >
> > > 'Save Installer Forms 11 Control Button
> > > Sub Save_Installer_Forms()
> > >
> > > ' Dim strFile As String
> > > ' Dim fileSaveName As Variant
> > > ' Dim myMsg As String
> > >
> > > strFile = "FORMS " & CLLI_Code_1.Value _ "This Block Turns Yellow"
> > > & Space(1) & TEO_No_1.Value _
> > > & Space(1) & CES_No_1.Value _
> > > & Space(1) & TEO_Appx_No_2.Value
> > >
> > > fileSaveName = Application.GetSaveAsFilename _
> > > (InitialFileName:=strFile, _
> > > fileFilter:="Excel Macro-Enabled Workbook(*.xlsm),(*.xlsm")
> > >
> > > If fileSaveName <> False Then
> > > ActiveWorkbook.SaveAs Filename:= _
> > > fileSaveName, _
> > > FileFormat:=xlOpenXMLWorkbookMacroEnabled, _
> > > CreateBackup:=False
> > > Else
> > > MsgBox prompt:=Engineer_2.Value & vbLf & "You canceled saving the
> > > Installer Form." & vbCrLf & _
> > > "Installer Form was not Saved.", _
> > > Title:="C.E.S."
> > >
> > > End If
> > >
> > > End Sub