+ Reply to Thread
Results 1 to 12 of 12

upload a new Module to overwrite previous module to update expriration date!

Hybrid View

JJFletcher upload a new Module to... 02-10-2021, 09:57 AM
rollis13 Re: upload a new Module to... 02-10-2021, 10:39 AM
JJFletcher Re: upload a new Module to... 02-10-2021, 10:45 AM
romperstomper Re: upload a new Module to... 02-10-2021, 11:37 AM
JJFletcher Re: upload a new Module to... 02-10-2021, 11:45 AM
romperstomper Re: upload a new Module to... 02-10-2021, 05:12 PM
JJFletcher Re: upload a new Module to... 02-10-2021, 11:55 AM
rollis13 Re: upload a new Module to... 02-10-2021, 01:07 PM
JJFletcher Re: upload a new Module to... 02-10-2021, 02:15 PM
romperstomper Re: upload a new Module to... 02-10-2021, 05:14 PM
JJFletcher Re: upload a new Module to... 02-10-2021, 07:08 PM
romperstomper Re: upload a new Module to... 02-10-2021, 07:41 PM
  1. #1
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    991

    upload a new Module to overwrite previous module to update expriration date!

    Hello,

    I found this expiration code and wanted to see if there is a way that when the time lapses that an update file can be sent to the User and reset the date in this code to the desired number of days in that update.

    This code shows a 30 day period and then the Excel file is stopped.

    Is there a way that a new Module can be loaded into the workbook and overwrite this Module and that would contain the new expiration date?


    ' Update this variable to set your own expiration period by number of days
    Private Const NUM_DAYS_UNTIL_EXPIRATION = 30
    
    Private Sub Expiration_Date()
    
        Dim ExpDate As String
        
        On Error Resume Next
        ExpDate = Mid(ThisWorkbook.Names("ExpDate").Value, 2)
        If Err.Number <> 0 Then
            ' Name doesn't exist.
            ' Calculate new expiration date
            ExpDate = CStr(DateSerial(Year(Now), _
                Month(Now), Day(Now) + NUM_DAYS_UNTIL_EXPIRATION))
            ' Create a named range and store the date in the named range
            ThisWorkbook.Names.Add Name:="ExpDate", _
                RefersTo:=Format(ExpDate, "short date"), _
                Visible:=False
            ' Save the file
            ThisWorkbook.Save
        End If
        
        ' Comapare today and expriation date
        If CDate(Now) > CDate(ExpDate) Then
            ' Expired
            MsgBox "Your StatsSystems subscription has EXPIRED, Please contact sales@statssystems.com to Re-Subscribe.", vbOKOnly
            ThisWorkbook.Close savechanges:=False
        End If
    
    End Sub
    Your thoughts?

    Thanks,

    John
    Last edited by JJFletcher; 02-10-2021 at 10:12 AM.

  2. #2
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    935

    Re: upload a new Module to overwrite previous module to update expriration date!

    Do you mean that you need to update this line of code: Private Const NUM_DAYS_UNTIL_EXPIRATION = 30 ?
    I would say that you need another approch, I read in your macro ExpDate = Mid(ThisWorkbook.Names("ExpDate").Value, 2) and this means that the information is part of the file name.

  3. #3
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    991

    Re: upload a new Module to overwrite previous module to update expriration date!

    Hi rollis13,
    I have been doing some research across the web and I understand that it may be possible to overwrite a module that is already part of the workbook.

    What solution do you recommend?

    Regards,

    John

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,131

    Re: upload a new Module to overwrite previous module to update expriration date!

    You don't need a new module, since the code itself is fine, it's just that the workbook contains a defined name with a date in it. You could presumably just send them a new copy of the workbook.
    Everyone who confuses correlation and causation ends up dead.

  5. #5
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    991

    Re: upload a new Module to overwrite previous module to update expriration date!

    Rorya,

    Thanks for your feedback...

    The code references a workbook named "ExpDate".

    My workbook in question has thousands of records and a large array of code involving up to 50 modules that run the workbook. Thus the importance to find a solution that updating the Module seems to be the logical approach that I want to investigate... this could be by possible a UserForm that can import the module and thus resetting the expiration date.

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,131

    Re: upload a new Module to overwrite previous module to update expriration date!

    Quote Originally Posted by JJFletcher View Post
    The code references a workbook named "ExpDate".
    No, it doesn’t. On startup, it checks for the existence of a defined name called ExpDate. If it’s not there, (which means it’s the first run of the code) it creates it and assigns the current date + 30 days to it, then saves the workbook. It then checks to see if today’s date after the date stored in that defined name. If it is, you get a message and the workbook closes.

  7. #7
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    991

    Re: upload a new Module to overwrite previous module to update expriration date!

    Also I discovered this potential solution in where the module is exported and then imported...

    Copy A Module From One Project To Another

    There is no direct way to copy a module from one project to another. To accomplish this task, you must export the module from the Source VBProject and then import that file into the Destination VBProject. The code below will do this. The function declaration is:

    Function CopyModule(ModuleName As String, _
    FromVBProject As VBIDE.VBProject, _
    ToVBProject As VBIDE.VBProject, _
    OverwriteExisting As Boolean) As Boolean

    ModuleName is the name of the module you want to copy from one project to another.

    FromVBProject is the VBProject that contains the module to be copied. This is the source VBProject.

    ToVBProject is the VBProject in to which the module is to be copied. This is the destination VBProject.

    OverwriteExisting indicates what to do if ModuleName already exists in the ToVBProject. If this is True the existing VBComponent will be removed from the ToVBProject. If this is False and the VBComponent already exists, the function does nothing and returns False.

    The function returns True if successful or False is an error occurs. The function will return False if any of the following are true:

    FromVBProject is nothing.
    ToVBProject is nothing.
    ModuleName is blank.
    FromVBProject is locked.
    ToVBProject is locked.
    ModuleName does not exist in FromVBProject.
    ModuleName exists in ToVBProject and OverwriteExisting is False.




    Function CopyModule(ModuleName As String, _
        FromVBProject As VBIDE.VBProject, _
        ToVBProject As VBIDE.VBProject, _
        OverwriteExisting As Boolean) As Boolean
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        ' CopyModule
        ' This function copies a module from one VBProject to
        ' another. It returns True if successful or  False
        ' if an error occurs.
        '
        ' Parameters:
        ' --------------------------------
        ' FromVBProject         The VBProject that contains the module
        '                       to be copied.
        '
        ' ToVBProject           The VBProject into which the module is
        '                       to be copied.
        '
        ' ModuleName            The name of the module to copy.
        '
        ' OverwriteExisting     If True, the VBComponent named ModuleName
        '                       in ToVBProject will be removed before
        '                       importing the module. If False and
        '                       a VBComponent named ModuleName exists
        '                       in ToVBProject, the code will return
        '                       False.
        '
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        
        Dim VBComp As VBIDE.VBComponent
        Dim FName As String
        Dim CompName As String
        Dim S As String
        Dim SlashPos As Long
        Dim ExtPos As Long
        Dim TempVBComp As VBIDE.VBComponent
        
        '''''''''''''''''''''''''''''''''''''''''''''
        ' Do some housekeeping validation.
        '''''''''''''''''''''''''''''''''''''''''''''
        If FromVBProject Is Nothing Then
            CopyModule = False
            Exit Function
        End If
        
        If Trim(ModuleName) = vbNullString Then
            CopyModule = False
            Exit Function
        End If
        
        If ToVBProject Is Nothing Then
            CopyModule = False
            Exit Function
        End If
        
        If FromVBProject.Protection = vbext_pp_locked Then
            CopyModule = False
            Exit Function
        End If
        
        If ToVBProject.Protection = vbext_pp_locked Then
            CopyModule = False
            Exit Function
        End If
        
        On Error Resume Next
        Set VBComp = FromVBProject.VBComponents(ModuleName)
        If Err.Number <> 0 Then
            CopyModule = False
            Exit Function
        End If
        
        ''''''''''''''''''''''''''''''''''''''''''''''''''''
        ' FName is the name of the temporary file to be
        ' used in the Export/Import code.
        ''''''''''''''''''''''''''''''''''''''''''''''''''''
        FName = Environ("Temp") & "\" & ModuleName & ".bas"
        If OverwriteExisting = True Then
            ''''''''''''''''''''''''''''''''''''''
            ' If OverwriteExisting is True, Kill
            ' the existing temp file and remove
            ' the existing VBComponent from the
            ' ToVBProject.
            ''''''''''''''''''''''''''''''''''''''
            If Dir(FName, vbNormal + vbHidden + vbSystem) <> vbNullString Then
                Err.Clear
                Kill FName
                If Err.Number <> 0 Then
                    CopyModule = False
                    Exit Function
                End If
            End If
            With ToVBProject.VBComponents
                .Remove .Item(ModuleName)
            End With
        Else
            '''''''''''''''''''''''''''''''''''''''''
            ' OverwriteExisting is False. If there is
            ' already a VBComponent named ModuleName,
            ' exit with a return code of False.
            ''''''''''''''''''''''''''''''''''''''''''
            Err.Clear
            Set VBComp = ToVBProject.VBComponents(ModuleName)
            If Err.Number <> 0 Then
                If Err.Number = 9 Then
                    ' module doesn't exist. ignore error.
                Else
                    ' other error. get out with return value of False
                    CopyModule = False
                    Exit Function
                End If
            End If
        End If
        
        ''''''''''''''''''''''''''''''''''''''''''''''''''''
        ' Do the Export and Import operation using FName
        ' and then Kill FName.
        ''''''''''''''''''''''''''''''''''''''''''''''''''''
        FromVBProject.VBComponents(ModuleName).Export Filename:=FName
        
        '''''''''''''''''''''''''''''''''''''
        ' Extract the module name from the
        ' export file name.
        '''''''''''''''''''''''''''''''''''''
        SlashPos = InStrRev(FName, "\")
        ExtPos = InStrRev(FName, ".")
        CompName = Mid(FName, SlashPos + 1, ExtPos - SlashPos - 1)
        
        ''''''''''''''''''''''''''''''''''''''''''''''
        ' Document modules (SheetX and ThisWorkbook)
        ' cannot be removed. So, if we are working with
        ' a document object, delete all code in that
        ' component and add the lines of FName
        ' back in to the module.
        ''''''''''''''''''''''''''''''''''''''''''''''
        Set VBComp = Nothing
        Set VBComp = ToVBProject.VBComponents(CompName)
        
        If VBComp Is Nothing Then
            ToVBProject.VBComponents.Import Filename:=FName
        Else
            If VBComp.Type = vbext_ct_Document Then
                ' VBComp is destination module
                Set TempVBComp = ToVBProject.VBComponents.Import(FName)
                ' TempVBComp is source module
                With VBComp.CodeModule
                    .DeleteLines 1, .CountOfLines
                    S = TempVBComp.CodeModule.Lines(1, TempVBComp.CodeModule.CountOfLines)
                    .InsertLines 1, S
                End With
                On Error GoTo 0
                ToVBProject.VBComponents.Remove TempVBComp
            End If
        End If
        Kill FName
        CopyModule = True
    End Function

    Thoughts??
    Last edited by JJFletcher; 02-10-2021 at 11:58 AM.

  8. #8
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    935

    Re: upload a new Module to overwrite previous module to update expriration date!

    Sorry, but managing vbe modules on external files goes fare beyond my minimal experience.

  9. #9
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    991

    Re: upload a new Module to overwrite previous module to update expriration date!

    Thank You!

    I appreciate you providing insight

  10. #10
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,131

    Re: upload a new Module to overwrite previous module to update expriration date!

    The upshot of that is that changing that module would have no effect whatsoever. You need to alter the date in the defined name stored in that workbook.

  11. #11
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    991

    Re: upload a new Module to overwrite previous module to update expriration date!

    rorya,

    Thanks for the feedback again... I will try to get this to be understandable so I can update the expiration date in the workbook with an import macro of some kind...

    Maybe another workbook (UserForm) that sends the update to the first workbook and changes(REfreshes) the expiration date... UGH!

    Regards,

    John

  12. #12
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,131

    Re: upload a new Module to overwrite previous module to update expriration date!

    In all honesty, this would be so easy to bypass, I’m not really sure why you bother, but it sounds like you should separate the code and data so that you can simply provide a fresh code workbook. Or use a separate licence key file in which you can hide a date string, so you just send them a new one of those.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Fiscal Year Date tracking / Expiration date tracker
    By TylerLucas227 in forum Excel General
    Replies: 3
    Last Post: 10-09-2019, 11:46 PM
  2. Adding Expiration Date and Days Left For Expiration Problem
    By Newmord in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-06-2018, 09:37 AM
  3. Calculate 1-year expiration date to the end of month of a date
    By Dietcoke1953 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-18-2016, 01:20 PM
  4. Expiration Date safe from changing computer's date
    By backyardfun in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-21-2014, 05:58 PM
  5. Expiration Date
    By stevenchaplin in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 04-23-2013, 03:56 PM
  6. set expiration date
    By nhat8121 in forum Excel General
    Replies: 13
    Last Post: 01-05-2007, 10:02 PM

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