+ Reply to Thread
Results 1 to 2 of 2

VBA Open FilePath from FTP location - Excel 2016 error

Hybrid View

  1. #1
    Registered User
    Join Date
    03-09-2017
    Location
    Denver, USA
    MS-Off Ver
    2013
    Posts
    2

    Question VBA Open FilePath from FTP location - Excel 2016 error

    Hi,

    I use Excel 2013 and have some VBA code to open up and copy data from an excel file on a FTP site. It works flawlessly in Excel 2013, however every time I try this on a computer with Excel 2016 the program closes and open a new sheet. I've identified the line of code which causes this to happen but am having trouble identifying how to make it work with Excel 2016.

    The line of code where it fails in 2016 is:
    Set RawWB = Workbooks.Open(Filename:=FilePath, ReadOnly:=True)

    I've verified that the user is able to open file on the FTP site so there is no FTP issue.

    Thanks!

    Sub RefreshData()
    
    
    Dim FilePath As String
    Dim RawWB As Workbook
    Dim feWB As Workbook
    Dim consolSH As Worksheet
    Dim dataPT As PivotTable
    Dim Rawtbl As ListObject
    Dim FTPuser As String, FTPpassword As String
    
    
    Set feWB = ActiveWorkbook
    Set consolSH = ActiveSheet
    
    
    Set Rawtbl = feWB.Sheets("Data").ListObjects("DataTable")
    
    
    feWB.Sheets("Data").Range("A2") = "A"
    'Delete all table rows except headers
      With Rawtbl.DataBodyRange
        If .Rows.Count > 1 Then
          .Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count).Rows.Delete
        End If
      End With
      Rawtbl.DataBodyRange.Rows(1).ClearContents
    
    
    'open up file selector to determine the path of the source data
    
    
    FTPuser = "unsername"
    FTPpassword = "password"
    
    
    FilePath = "ftp://" & FTPuser & ":" & FTPpassword & "@ftp.XXXXXXX.com/XXXXXXXX/XXXXXXXXXX/XXXXXXXXXXXX.EXCEL"
    
    
    '''''HERE is where the code fails, closes/repoens Excel'''''''''''''''''''''
    Set RawWB = Workbooks.Open(Filename:=FilePath, ReadOnly:=True)
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    RawWB.Activate
    
    
    'If there are any merged cells then they will be unmerged and the row with empty data will be deleted
    RawWB.Sheets(1).Cells.UnMerge
    On Error Resume Next
    RawWB.Sheets(1).Columns("A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    RawWB.Sheets(1).Range("C1").Value = "."
    RawWB.Sheets(1).Columns("C").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    
    RawWB.Sheets(1).Range(Range("A3", Range("A3").End(xlToRight)), Range("A3", Range("A3").End(xlToRight)).End(xlDown)).Copy Destination:=feWB.Sheets("Data").Range("A2")
    
    
    'Close source data WB
    RawWB.Close savechanges:=False
    
    
    'Refresh the pivot table
    feWB.Sheets(consolSH.Name).Activate
    
    
    Set dataPT = feWB.Sheets(consolSH.Name).PivotTables("ConsolPT")
        dataPT.RefreshTable
    
    
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    
    
    MsgBox "Inventory File Updated"
    
    
    End Sub

  2. #2
    Registered User
    Join Date
    03-09-2017
    Location
    Denver, USA
    MS-Off Ver
    2013
    Posts
    2

    Re: VBA Open FilePath from FTP location - Excel 2016 error

    Thoughts on this?

+ 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. Excel 2016 Hyperlinks Won't Open
    By drew.lewis.rtr in forum Excel General
    Replies: 4
    Last Post: 08-17-2017, 12:25 AM
  2. Excel 2016 Mac - Open File Macro
    By DylanM in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-10-2016, 08:53 AM
  3. Replies: 1
    Last Post: 08-24-2016, 03:55 AM
  4. Mac excel 2016, vba copy file from one location to sandbox location
    By sujithy007 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-11-2016, 12:01 PM
  5. Replies: 2
    Last Post: 02-21-2016, 03:33 AM
  6. Replies: 0
    Last Post: 04-14-2014, 02:12 AM
  7. [SOLVED] Trying to get the filepath on "Open", but get filepath of a temporary file instead
    By ianpwilliams in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 08-22-2013, 12:27 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