+ Reply to Thread
Results 1 to 3 of 3

NEWBIE Alert! Macro Run at workbook Startup

  1. #1
    Registered User
    Join Date
    09-06-2006
    Posts
    2

    Question NEWBIE Alert! Macro Run at workbook Startup

    Hello all,

    I am attempting to get the following macro stored in a workbook to start when the .xlt is opened. I have no idea where to begin or how to do it, any help would be greatly appreciated.

    Public Function NextSeqNumber(Optional sFileName As String, Optional nSeqNumber As Long = -1) As Long
    Const sDEFAULT_PATH As String = "\\tpadc\intranet\Plot Ticket"
    Const sDEFAULT_FNAME As String = "defaultseq.txt"
    Dim nFileNumber As Long

    nFileNumber = FreeFile
    If sFileName = "" Then sFileName = sDEFAULT_FNAME
    If InStr(sFileName, Application.PathSeparator) = 0 Then _
    sFileName = sDEFAULT_PATH & Application.PathSeparator & sFileName
    If nSeqNumber = -1& Then
    If Dir(sFileName) <> "" Then
    Open sFileName For Input As nFileNumber
    Input #nFileNumber, nSeqNumber
    nSeqNumber = nSeqNumber + 1&
    Close nFileNumber
    Else
    nSeqNumber = 1&
    End If
    End If
    On Error GoTo PathError
    Open sFileName For Output As nFileNumber
    On Error GoTo 0
    Print #nFileNumber, nSeqNumber
    Close nFileNumber
    NextSeqNumber = nSeqNumber
    Exit Function
    PathError:
    NextSeqNumber = -1&
    End Function


    Public Sub SetUpNewClient()
    With ThisWorkbook.Sheets(1)
    .Range("V58").Value = NextSeqNumber
    End With
    End Sub

  2. #2
    Registered User
    Join Date
    09-06-2006
    Posts
    2
    You need to name the macro Auto_Open.

    Keep in mind that the macro security level should be medium or low.

  3. #3
    Registered User
    Join Date
    09-06-2006
    Posts
    2
    Nevermind, I found what I was looking for!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1