Closed Thread
Results 1 to 6 of 6

macro merge

Hybrid View

  1. #1
    Registered User
    Join Date
    05-07-2012
    Location
    Dhaka
    MS-Off Ver
    Excel 2016
    Posts
    80

    macro merge

    Hi!
    I am really new to macro and I need to have the first macro merge in to 2nd macro (I need to disable the SAVE/SAVE AS option for integrity of the workbook)

    ==================================================================
    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    
        MsgBox "You can't save this workbook!"
        Cancel = True
    
    End Sub
    ==================================================================




    ==================================================================
    Option Explicit
    
    Const WelcomePage = "Macros"
    
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
         'Turn off events to prevent unwanted loops
        Application.EnableEvents = False
    
         'Evaluate if workbook is saved and emulate default propmts
        With ThisWorkbook
            If Not .Saved Then
                Select Case MsgBox("Do you want to save the changes you made to '" & .Name & "'?", _
                    vbYesNoCancel + vbExclamation)
                Case Is = vbYes
                     'Call customized save routine
                    Call CustomSave
                Case Is = vbNo
                     'Do not save
                Case Is = vbCancel
                     'Set up procedure to cancel close
                    Cancel = True
                End Select
            End If
    
             'If Cancel was clicked, turn events back on and cancel close,
             'otherwise close the workbook without saving further changes
            If Not Cancel = True Then
                .Saved = True
                Application.EnableEvents = True
                .Close savechanges:=False
            Else
                Application.EnableEvents = True
            End If
        End With
    End Sub
    
    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    
    MsgBox "If you save this file in local then it wont update in future!"
    
    
    
         'Turn off events to prevent unwanted loops
        Application.EnableEvents = False
    
         'Call customized save routine and set workbook's saved property to true
         '(To cancel regular saving)
        Call CustomSave(SaveAsUI)
        Cancel = True
    
         'Turn events back on an set saved property to true
        Application.EnableEvents = True
        ThisWorkbook.Saved = True
    End Sub
    
    Private Sub Workbook_Open()
         'Unhide all worksheets
        Application.ScreenUpdating = False
        Call ShowAllSheets
        Application.ScreenUpdating = True
    End Sub
    
    Private Sub CustomSave(Optional SaveAs As Boolean)
        Dim ws As Worksheet, aWs As Worksheet, newFname As String
         'Turn off screen flashing
        Application.ScreenUpdating = False
    
         'Record active worksheet
        Set aWs = ActiveSheet
    
         'Hide all sheets
        Call HideAllSheets
    
         'Save workbook directly or prompt for saveas filename
        If SaveAs = True Then
            newFname = Application.GetSaveAsFilename( _
            fileFilter:="Excel Files (*.xls), *.xls")
            If Not newFname = "False" Then ThisWorkbook.SaveAs newFname
        Else
            ThisWorkbook.Save
        End If
    
         'Restore file to where user was
        Call ShowAllSheets
        aWs.Activate
    
         'Restore screen updates
        Application.ScreenUpdating = True
    End Sub
    
    Private Sub HideAllSheets()
         'Hide all worksheets except the macro welcome page
        Dim ws As Worksheet
    
        Worksheets(WelcomePage).Visible = xlSheetVisible
    
        For Each ws In ThisWorkbook.Worksheets
            If Not ws.Name = WelcomePage Then ws.Visible = xlSheetVeryHidden
        Next ws
    
        Worksheets(WelcomePage).Activate
    End Sub
    
    Private Sub ShowAllSheets()
         'Show all worksheets except the macro welcome page
    
        Dim ws As Worksheet
    
        For Each ws In ThisWorkbook.Worksheets
            If Not ws.Name = WelcomePage Then ws.Visible = xlSheetVisible
        Next ws
    
        Worksheets(WelcomePage).Visible = xlSheetVeryHidden
    End Sub
    ==================================================================

    I hope someone kind enough to help me on this ☺

    Thank you

  2. #2
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: macro merge

    Do you need to merge macros?

    You could save the file that is sent to the users as a "Read Only" with modification rights password protected
    This prevents the user from saving any modifications to the file

    ReadOnly.jpg
    Last edited by Kevin#; 05-21-2016 at 09:00 AM.
    If a response has helped then please consider rating it by clicking on *Add Reputation below the post
    When your issue has been resolved don't forget to mark the thread SOLVED (click Thread Tools at top of thread)

  3. #3
    Registered User
    Join Date
    05-07-2012
    Location
    Dhaka
    MS-Off Ver
    Excel 2016
    Posts
    80
    Quote Originally Posted by Kevin# View Post
    Do you need to merge macros?

    You could save the file that is sent to the users as a "Read Only" with modification rights password protected
    This prevents the user from saving any modifications to the file

    Attachment 462015
    until now, i am using this method but problem is they use the save as to saving it in local and then the file doesnt update

  4. #4
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: macro merge

    1. Which file does not update?
    2. Why does it not update?
    3. Where is local? On their C: drive?

  5. #5
    Registered User
    Join Date
    05-07-2012
    Location
    Dhaka
    MS-Off Ver
    Excel 2016
    Posts
    80

    Re: macro merge

    1. its a xlsx file. this file returns data from a external excel file which is in LAN server
    2. external file path doesnt match (maybe a absolute/relative path conflict)
    3. local mean any of the 13 area's users local machine

    i need to put both the file in LAN server to make it work. its also matter of security

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: macro merge

    Welcome to the Forum, unfortunately:

    This is a duplicate post and as such does not comply with Rule 5 of our forum rules. This thread will now be closed, you may continue in your other thread.

    Thread Closed.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

Closed Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Mail Merge - Merge fields lister macro
    By adil.master in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-26-2015, 10:33 AM
  2. [SOLVED] Macro - Merge cell if same BL and sum and merge same BL
    By ash3angel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-08-2015, 12:59 AM
  3. Macro to merge
    By escapes88 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-22-2014, 10:30 AM
  4. [SOLVED] Macro to merge duplicate rows unique values - current macro not working
    By aimeecrystalaid in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-06-2013, 03:42 PM
  5. how do i merge two macro into one ?
    By accountant. in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-31-2011, 12:31 PM
  6. Can't merge my mail macro and signature macro
    By JohannesEngelbert in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-14-2010, 01:54 PM
  7. Macro to Merge and Sum Rows
    By MrGPeter in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-15-2005, 04:35 AM

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