Where do I put this macro

ghrek

Active Member
Joined
Jul 29, 2005
Messages
427
Hi

I was given a macro that should open a sharepoint file. I believe that it shouldnt be in the workbook that I open but somewhere else.

Where do I put it? Tried putting in new workbook and running and says the file dont exist but it is in sharepoint.

VBA Code:
Sub OpenAndCloseWBFromSharePointFolder()

'If nobody has the file checked out
If Workbooks.CanCheckOut("https://arrivagroup.sharepoint.com/:x:/r/teams/O365GRP-StationAccounts/Shared%20Documents/General/test.xlsm?d=wdcc3d7b614284396a2cb4564704dff53&cs") = True Then
Application.DisplayAlerts = False

'Open the file on the SharePoint server
Workbooks.Open Filename:="https://arrivagroup.sharepoint.com/:x:/r/teams/O365GRP-StationAccounts/Shared%20Documents/General/test.xlsm?d=wdcc3d7b614284396a2cb4564704dff53&csF", UpdateLinks:=xlUpdateLinksNever

'Close the workbook
Workbooks("test.xlsm").Close
Application.DisplayAlerts = True
Else
Application.DisplayAlerts = False

'Open the File to check if you already have it checked out
Workbooks.Open Filename:="https://arrivagroup.sharepoint.com/:x:/r/teams/O365GRP-StationAccounts/Shared%20Documents/General/test.xlsm?d=wdcc3d7b614284396a2cb4564704dff53&cs", UpdateLinks:=xlUpdateLinksNever

'See if doc can be checked in
If Application.Workbooks("test.xlsm").CanCheckIn Then

'Check In, Save and Close
Application.Workbooks("ExcelList.xlsb").CheckIn SaveChanges:=True, Comments:="Checked-In before Delete"

'Open the file again
Workbooks.Open Filename:="https://arrivagroup.sharepoint.com/:x:/r/teams/O365GRP-StationAccounts/Shared%20Documents/General/test.xlsm?d=wdcc3d7b614284396a2cb4564704dff53&cs"

'Close the workbook
Workbooks("test.xlsm").Close
End If
End If

End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
My SP experience is limited, but I'm fairly certain you cannot access a SP file using its web address. You need the server name and path to the file. If you can navigate to the SP server with Windows File Explorer you should be able to look at its properties and get the server name.
 
Upvote 0

Forum statistics

Threads
1,224,551
Messages
6,179,470
Members
452,915
Latest member
hannnahheileen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top