Beyond AUTO_OPEN

G

Guest

My question regarding code below is that I'm not sure how/where to place the code. At this point, the extent of my VBA experience is AUTO_OPEN and AUTO_CLOSE. I would like to call his code as the workbook is opening

How do I place the code? ...within AUTO_OPEN? ...called from AUTO_OPEN? ...do I create a standard module or class module or function and place the code there??? Appreciate any suggestions out there

Thanks, Warren R
--------------------------------------------------------
Here is the code to pull C: Volume Serial Number given to me from Rob van Gelder..

Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA"
(ByVal lpRootPathName As String,
ByVal lpVolumeNameBuffer As String,
ByVal nVolumeNameSize As Long
lpVolumeSerialNumber As Long,
lpMaximumComponentLength As Long
lpFileSystemFlags As Long,
ByVal lpFileSystemNameBuffer As String,
ByVal nFileSystemNameSize As Long) As Lon

Sub test(
Const cMaxPath = 256, cDrive = "C:\

Dim strTemp As String, lngRet As Lon
Dim lngVolSerial As Long, strVolName As String * cMaxPat
Dim lngMaxCompLen As Long, lngFileSysFlags As Lon
Dim strFileSysName As String * cMaxPat

lngRet = GetVolumeInformation(cDrive, strVolName, cMaxPath, lngTemp,
lngMaxCompLen, lngFileSysFlags, strFileSysName, cMaxPath
strTemp = Format(Hex(lngTemp), "00000000"
strTemp = Left(strTemp, 4) & "-" & Right(strTemp, 4

MsgBox strTem
End Su
 
B

Bob Phillips

Depend upon how you want it to run. If you want it to run when the workbook
opens, rename the sub Test to Auto_Open. If you want it to be activated by a
button, just assign Test to it.

Put the code in a standard code module.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

WarrenR said:
My question regarding code below is that I'm not sure how/where to place
the code. At this point, the extent of my VBA experience is AUTO_OPEN and
AUTO_CLOSE. I would like to call his code as the workbook is opening.
How do I place the code? ...within AUTO_OPEN? ...called from AUTO_OPEN?
....do I create a standard module or class module or function and place the
code there??? Appreciate any suggestions out there?
 
T

Tushar Mehta

Also see the response(s) in the original discussion.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top