Hi Microsoft Support,
I have an Excel workbook with a VBA macro that loads or inserts pictures from a folder.
When the pictures are stored inside the same folder as the Excel workbook, the macro loads them normally and no “Grant Access” prompt appears.
However, the image files are large, and keeping them in the Excel folder uses too much storage space on my laptop. To save laptop storage, I decided to store the pictures on an external HDD or on a NAS through an SMB network share.
The issue is that when the macro loads pictures from the external HDD or SMB/NAS location, Excel displays a “Grant Access” prompt every time. This happens even though I already have permission to access the folder.
Could you please advise how to prevent the repeated “Grant Access” prompt while allowing the VBA macro to load images from the external HDD or SMB/NAS folder? Are there recommended Excel settings, macOS privacy permissions, SMB-share settings, or VBA code changes for this?
I have attached the VBA macro code used to load the pictures for your reference.
Environment details:
- Excel version: [version]
- macOS version: [version]
- Image source: External HDD / NAS SMB network share
Thank you.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim shp As Shape
Dim rng As Range, c As Range
Dim img As String, imgName As String
Dim lastRow As Long
Dim formulaD As String
Dim formulaE As String
Dim formulaF As String
Dim formulaG As String
Dim i As Long
Dim seqNum As Long
Dim rowRange As Range
Dim ws As Worksheet
Const filepath As String = "/Volumes/test/PICTURES/"
Set ws = Me
' Only run code if changes are made in column C
If Intersect(Target, ws.Columns("C")) Is Nothing Then Exit Sub
' Optimize performance
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
' Handle image and text update
Set rng = Intersect(Target, ws.Range("C2:C" & ws.Rows.Count))
If Not rng Is Nothing Then
For Each c In rng
With c.offset(0, -1)
imgName = "PictureAt" & .Address
On Error Resume Next
' Delete the existing image if it exists
If ws.Shapes.Count > 0 Then ws.Shapes(imgName).Delete
On Error GoTo 0
' Determine image path
img = filepath & c.Value & ".jpg"
' Clear cell content and manage "NO PICTURE AVAILABLE"
If IsEmpty(c.Value) Or Dir(img) = "" Then
.ClearContents
If IsEmpty(c.Value) Then
' If cell in column C is empty, clear corresponding row from columns A to C
ws.Range("A" & c.Row & ":C" & c.Row).ClearContents
' Remove borders if column C is empty
ws.Range(ws.Cells(c.Row, "A"), ws.Cells(c.Row, "C")).Borders(xlEdgeBottom).LineStyle = xlNone
ws.Range(ws.Cells(c.Row, "A"), ws.Cells(c.Row, "C")).Borders(xlEdgeTop).LineStyle = xlNone
ws.Range(ws.Cells(c.Row, "A"), ws.Cells(c.Row, "C")).Borders(xlEdgeLeft).LineStyle = xlNone
ws.Range(ws.Cells(c.Row, "A"), ws.Cells(c.Row, "C")).Borders(xlEdgeRight).LineStyle = xlNone
ws.Range(ws.Cells(c.Row, "A"), ws.Cells(c.Row, "C")).Borders(xlInsideVertical).LineStyle = xlNone
ws.Range(ws.Cells(c.Row, "A"), ws.Cells(c.Row, "C")).Borders(xlInsideHorizontal).LineStyle = xlNone
' Maintain the current row height
ws.Rows(c.Row).RowHeight = ws.Rows(c.Row).RowHeight
Else
' Cell in column C has a value but no picture found
.Value = "NO PICTURE AVAILABLE"
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = True
' Maintain the current row height
ws.Rows(c.Row).RowHeight = ws.Rows(c.Row).RowHeight
End If
Else
' Add picture if it exists
.ClearContents
If Dir(img) <> "" Then
Dim pic As Picture
Set pic = ws.Pictures.Insert(img)
pic.Left = .Left
pic.Top = .Top
pic.ShapeRange.LockAspectRatio = msoTrue
pic.ShapeRange.Height = .Height - 4
End If
End If
End With
Next c
End If
' Add borders to columns A to C if column C is not empty
For Each c In rng
If Not IsEmpty(c.Value) Then
With ws.Range(ws.Cells(c.Row, "A"), ws.Cells(c.Row, "C")).Borders
.Item(xlEdgeBottom).LineStyle = xlContinuous
.Item(xlEdgeTop).LineStyle = xlContinuous
.Item(xlEdgeLeft).LineStyle = xlContinuous
.Item(xlEdgeRight).LineStyle = xlContinuous
.Item(xlInsideVertical).LineStyle = xlContinuous
.Item(xlInsideHorizontal).LineStyle = xlContinuous
End With
End If
Next c
' Add sequence numbers in column A
seqNum = 1
lastRow = ws.Cells(ws.Rows.Count, "C").End(xlUp).Row
For i = 2 To lastRow
Set rowRange = ws.Range("A" & i & ":C" & i)
If Application.WorksheetFunction.CountA(rowRange) > 0 Then
ws.Cells(i, "A").Value = seqNum
seqNum = seqNum + 1
Else
ws.Cells(i, "A").Value = "" ' Clear the cell if column C is empty
End If
Next i
' Restore settings
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub