Home

Macro to insert photos in cells

%3CLINGO-SUB%20id%3D%22lingo-sub-799290%22%20slang%3D%22en-US%22%3EMacro%20to%20insert%20photos%20in%20cells%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-799290%22%20slang%3D%22en-US%22%3E(Please%20see%20attachment%20for%20Macro%20code%2C%20I%20can't%20figure%20out%20how%20to%20start%20each%20line%20on%20a%20new%20line%20in%20a%20post)%20Hi%20there%2C%20I%20have%20a%20macro%20that%20inserts%20photos%20into%20cells%2C%20activated%20using%20a%20button.%20The%20issue%20is%20that%20when%20the%20spreadsheet%20is%20shared%20the%20photos%20are%20not%20appearing%20and%20instead%20an%20error%20message%20appears%20in%20their%20place.%20The%20issue%20appears%20to%20be%20that%20it%20is%20referencing%20the%20photo%20on%20the%20local%20drive%20on%20the%20computer.%20A%20solution%20I%20have%20found%20is%20to%20Copy%20-%20Paste%20as%20Picture%20but%20this%20adds%20an%20extra%20step.%20I'm%20wondering%20if%20there%20is%20some%20way%20to%20set%20up%20the%20macro%20so%20that%20it%20inserts%20the%20photos%20in%20a%20way%20that%20allows%20for%20the%20spreadsheet%20to%20be%20shared%20without%20losing%20the%20photos%3F%20Any%20help%20would%20be%20much%20appreciated!%20Please%20see%20attachment%20if%20the%20macro%20below%20is%20not%20displaying%20properly.%20Sub%20insertpic()%20Dim%20sFile%20As%20Variant%2C%20r%20As%20Range%20sFile%20%3D%20Application.GetOpenFilename(FileFilter%3A%3D%22Pic%20Files%20(*.jpg%3B*.bmp)%2C%20*.jpg%3B*.bmp%22%2C%20Title%3A%3D%22Browse%20to%20select%20a%20picture%22)%20If%20sFile%20%3D%20False%20Then%20Exit%20Sub%20On%20Error%20Resume%20Next%20Set%20r%20%3D%20Application.InputBox(%22Click%20in%20the%20cell%20to%20hold%20the%20picture%22%2C%20Type%3A%3D8)%20On%20Error%20GoTo%200%20If%20r%20Is%20Nothing%20Then%20Exit%20Sub%20If%20r.Count%20%26gt%3B%201%20Then%20Exit%20Sub%20ActiveSheet.Pictures.Insert%20(sFile)%20With%20ActiveSheet.Shapes(ActiveSheet.Shapes.Count)%20.LockAspectRatio%20%3D%20True%20.Top%20%3D%20r.Top%20.Left%20%3D%20r.Left%20.Height%20%3D%20200%20End%20With%20End%20Sub%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-799290%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
SamFojbk
Frequent Visitor
(Please see attachment for Macro code, I can't figure out how to start each line on a new line in a post) Hi there, I have a macro that inserts photos into cells, activated using a button. The issue is that when the spreadsheet is shared the photos are not appearing and instead an error message appears in their place. The issue appears to be that it is referencing the photo on the local drive on the computer. A solution I have found is to Copy - Paste as Picture but this adds an extra step. I'm wondering if there is some way to set up the macro so that it inserts the photos in a way that allows for the spreadsheet to be shared without losing the photos? Any help would be much appreciated! Please see attachment if the macro below is not displaying properly. Sub insertpic() Dim sFile As Variant, r As Range sFile = Application.GetOpenFilename(FileFilter:="Pic Files (*.jpg;*.bmp), *.jpg;*.bmp", Title:="Browse to select a picture") If sFile = False Then Exit Sub On Error Resume Next Set r = Application.InputBox("Click in the cell to hold the picture", Type:=8) On Error GoTo 0 If r Is Nothing Then Exit Sub If r.Count > 1 Then Exit Sub ActiveSheet.Pictures.Insert (sFile) With ActiveSheet.Shapes(ActiveSheet.Shapes.Count) .LockAspectRatio = True .Top = r.Top .Left = r.Left .Height = 200 End With End Sub
Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
35 Replies
Extentions Synchronization
Deleted in Discussions on
3 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies