Home > Mobile >  Running a macro on a local PC - Excel file in sharepoint
Running a macro on a local PC - Excel file in sharepoint

Time:08-16

I have an macro in Excel designed to refresh all data when opening the file, as well as update it every 30 minutes - this works as it should. The file is in a SharePoint folder, so that myself and my colleagues can access it at the same time.

My issue is that that I need the macro to only run on my PC, and not everyone else who has the file open. The reason for this is a long explanation, but essentially they are not able to update the data. If they do try to update it, error messages will appear.

Can anyone help with limiting the macro to only run on my PC, by somehow recognising me? Other ideas? Thanks a lot in advance.

Option Explicit
Dim RunTimer As Date
Sub Refresh()
RunTimer = Now   TimeValue("00:30:00")
Application.OnTime RunTimer, "Refresh"
ActiveWorkbook.RefreshAll
End Sub

Macro which starts the routine when opening the file:
Private Sub Workbook_Open()
Call Refresh
End Sub

This macro is based on the tutorial by "Computergaga" on YouTube.

CodePudding user response:

If you are logged in Excel then you could use:

If Application.UserName = "joachimu" then
    Call Refresh
End If

Alternatively instead Application.UserName you could use Environ("username")

  • Related