VBA for BeforeSave that works with Sharepoint

125ml

New Member
Joined
Jun 16, 2015
Messages
3
Hi,

I have some VBA code that I have been using successfully on a file, but now have moved to storing this file on a SharePoint.
Now I'm getting a Compile Error ; Type Mismatch with the first line of the code (the BeforeSave) highlighted.

Does anyone know what I should change this to?
I want the VBA to run at the same point (when someone saves the file) but to play nicely with SharePoint.

Here is my code:

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
'
' Archive notes when something new is available
'




Dim i As Long
Dim ii As Long
Dim LastRow As Long
Dim wd As Workbook
Dim sht1 As Worksheet
Dim sht2 As Worksheet
Set wb = ThisWorkbook
Set sht1 = wb.Sheets("Tracker")
Set sht2 = wb.Sheets("archive")
LastRow = 50
ii = 2
Application.Screenupdating = False


For i = 6 To LastRow




    If IsEmpty(sht1.Range("O" & i)) Then
        
    Else
        sht2.Range("B" & ii) = sht1.Range("N" & i) & Chr(10) & sht2.Range("B" & ii)
        sht1.Range("N" & i) = DateTime & " " & sht1.Range("O" & i)
        sht1.Range("O" & i).Clear
    
    End If
    ii = ii + 1
Next i


Application.Screenupdating = True




End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Check your declaration:

Dim wb As Workbook (not wd as in your posted code)

Set wb = ThisWorkbook
 
Upvote 0
Thanks for the spot, doesn't fix the issue though.
Still getting Type mismatch on the Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) line

 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,488
Members
448,967
Latest member
visheshkotha

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