+ Reply to Thread
Results 1 to 9 of 9

VBA Mac - Downloading image not working (But working in Windows)

Hybrid View

sthiru VBA Mac - Downloading image... 10-19-2014, 10:54 AM
Richard Buttrey Re: VBA Mac - Downloading... 10-19-2014, 11:29 AM
sthiru Re: VBA Mac - Downloading... 10-19-2014, 12:03 PM
Richard Buttrey Re: VBA Mac - Downloading... 10-19-2014, 02:56 PM
sthiru Re: VBA Mac - Downloading... 10-19-2014, 10:45 PM
romperstomper Re: VBA Mac - Downloading... 10-20-2014, 08:10 AM
sthiru Re: VBA Mac - Downloading... 10-20-2014, 10:05 AM
romperstomper Re: VBA Mac - Downloading... 10-20-2014, 10:11 AM
sthiru Re: VBA Mac - Downloading... 10-20-2014, 10:25 AM
  1. #1
    Registered User
    Join Date
    05-22-2011
    Location
    chennai
    MS-Off Ver
    Excel 2003
    Posts
    71

    VBA Mac - Downloading image not working (But working in Windows)

    Hi

    I have created a macro file to download images from website to folder - its working fine in Windows but its not working in Excel for Mac 2011, OSX 10.9.5 (Mavericks).

    Also attached file.

    This is the code that i have used - Is there any other way to download from url using vba excel.

    Option Explicit
    
    Private Declare Function URLDownloadToFile Lib "urlmon" _
    Alias "URLDownloadToFileA" (ByVal pCaller As Long, _
    ByVal szURL As String, ByVal szFileName As String, _
    ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
    
    Dim Ret As Long
    
    '~~> This is where the images will be saved. Change as applicable
    Const FolderName As String = "C:\Users\MattGold\Desktop\Images\"
    
    Sub Sample()
        Dim ws As Worksheet
        Dim LastRow As Long, i As Long
        Dim strPath As String
        
    
        '~~> Name of the sheet which has the list
        Set ws = Sheets("LOAD")
    
        LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
    
        For i = 2 To LastRow '<~~ 2 because row 1 has headers
            strPath = FolderName & ws.Range("A" & i).Value & ".jpg"
    
            Ret = URLDownloadToFile(0, ws.Range("B" & i).Value, strPath, 0, 0)
    
            If Ret = 0 Then
                ws.Range("C" & i).Value = "File successfully downloaded"
            Else
                ws.Range("C" & i).Value = "Unable to download the file"
            End If
        Next i
    End Sub
    Please help me on this.

    Thanks
    Thiru
    Attached Files Attached Files

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA Mac - Downloading image not working (But working in Windows)

    Hi,

    There are many instances where the VBA syntax of Mac differs to Windows, but the first line that stands out in your code is the path separator \. In the MAc this is the pipe | symbol

    Try using an IF test to recognise the OS and set the variable as necessary
     If Application.OperatingSystem Like "*mac" Then
            Const FolderName As String = "C:Users|MattGold|Desktop|Images|"
        Else
            Const FolderName As String = "C:\Users\MattGold\Desktop\Images\"
     End If
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    05-22-2011
    Location
    chennai
    MS-Off Ver
    Excel 2003
    Posts
    71

    Re: VBA Mac - Downloading image not working (But working in Windows)

    No sir! i'm getting different message as "File not found: urlmon"

    Could you please help me on this?

    Thanks
    Thiru




    Quote Originally Posted by Richard Buttrey View Post
    Hi,

    There are many instances where the VBA syntax of Mac differs to Windows, but the first line that stands out in your code is the path separator \. In the MAc this is the pipe | symbol

    Try using an IF test to recognise the OS and set the variable as necessary
     If Application.OperatingSystem Like "*mac" Then
            Const FolderName As String = "C:Users|MattGold|Desktop|Images|"
        Else
            Const FolderName As String = "C:\Users\MattGold\Desktop\Images\"
     End If

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA Mac - Downloading image not working (But working in Windows)

    Hi,

    Time to upload the workbook for a more definitive answer methinks!

  5. #5
    Registered User
    Join Date
    05-22-2011
    Location
    chennai
    MS-Off Ver
    Excel 2003
    Posts
    71

    Re: VBA Mac - Downloading image not working (But working in Windows)

    Here you go - i have attached workbook.

    Please help me on this sir!

    Thanks
    Thiru


    Quote Originally Posted by Richard Buttrey View Post
    Hi,

    Time to upload the workbook for a more definitive answer methinks!
    Attached Files Attached Files

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,975

    Re: VBA Mac - Downloading image not working (But working in Windows)

    You can't use a Windows API call on a Mac.
    Everyone who confuses correlation and causation ends up dead.

  7. #7
    Registered User
    Join Date
    05-22-2011
    Location
    chennai
    MS-Off Ver
    Excel 2003
    Posts
    71

    Re: VBA Mac - Downloading image not working (But working in Windows)

    Hi Romperstomper

    oh...Ok - could you please help me on the vba mac script to save the image from url - Please.

    Thanks
    Thiru

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,975

    Re: VBA Mac - Downloading image not working (But working in Windows)

    Afraid not - you'd need AppleScript and I have little to no knowledge of that.

  9. #9
    Registered User
    Join Date
    05-22-2011
    Location
    chennai
    MS-Off Ver
    Excel 2003
    Posts
    71

    Re: VBA Mac - Downloading image not working (But working in Windows)

    Its ok not a problem - Thank you so much.

    Thanks
    Thiru

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA Mac - Downloading image not working (But working in Windows)
    By sthiru in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-18-2014, 08:45 AM
  2. VBA code Error after changed to windows 7, working fine in windows XP before
    By Faridwahidi in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-11-2014, 06:23 AM
  3. Macros created in Windows XP not opening /working in Windows 7
    By Janane in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-18-2012, 04:28 AM
  4. Power pivot is not downloading, or working
    By AB33 in forum Excel General
    Replies: 0
    Last Post: 08-06-2012, 12:47 PM
  5. ocde working in one windows login but stopped working in another.
    By rama1209 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-02-2011, 08:38 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1