+ Reply to Thread
Results 1 to 2 of 2

VBA Code Not Running On All Computers

  1. #1
    Registered User
    Join Date
    02-05-2019
    Location
    Pittsburgh, PA
    MS-Off Ver
    Office 365
    Posts
    2

    VBA Code Not Running On All Computers

    Some background. This file is being used by someone in Mexico, so I don't know if that has anything to do with the error she's receiving. I wrote this using Office 365. It works perfectly on my computer and another computer in my house using Office 365. I tried on Excel for Mac computer and it worked fine. I tried it on a friend's computer using Excel 2013 and I get the same error. The error says:

    An error has been produced 1004 in running time
    This name is already used. Try with a different one

    When I click on debug, it highlights this line of code: "ws.Copy After:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count)"

    I made sure the path was correct for any computer we tried it on. The error occurs right after it's copying the last of the 4 files.

    What the code does is copies the worksheets from the other four files in the folder to the file called "BD - Inversion Comunitaria EDR", then adds two new worksheets at the end. It never gets to the point of adding the new worksheets.

    I have the following VBA code:

    Sub ICEDR()

    Dim Path As String
    Path = "F:\Excel Help\Edna\Inversion Comunitaria EDR\"

    Dim FileName As String
    FileName = Dir(Path & "*.xlsx")

    Dim ws As Worksheet

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    Do While FileName <> ""
    Workbooks.Open Path & FileName
    For Each ws In ActiveWorkbook.Sheets
    ws.Copy After:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count)
    Next ws
    Workbooks(FileName).Close
    FileName = Dir()
    Loop

    Worksheets(1).Delete

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    Sheets.Add After:=ActiveSheet
    ActiveSheet.Name = "Peticiones"

    Sheets.Add After:=ActiveSheet
    ActiveSheet.Name = "Proyectos"

    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: VBA Code Not Running On All Computers

    What you can try is to debug it on the friends pc and check each line/variable prior to that line and make sure that the values are in fact changing as expect as it goes thru each file.
    Seems you are looking at all excel files within a folder and executing your code,

+ 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. [SOLVED] VBA code crashes Excel for only one out of 3 Computers Using it
    By CRIMEDOG in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-24-2018, 11:19 AM
  2. [SOLVED] Excel Macro Runs on Some Computers, Not All- Stalls for computers where it fails to run
    By jamie.harris in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 05-25-2018, 04:54 PM
  3. Running Outlook on Multiple Computers
    By Mr_Phil in forum Outlook Formatting & Functions
    Replies: 3
    Last Post: 12-05-2016, 04:15 PM
  4. Excel/VBA running in different computers and MAC
    By hanif in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-25-2016, 07:22 AM
  5. Run time error 9 while running on other computers
    By furqanglb in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 02-28-2015, 01:34 PM
  6. VBA HTML not running on all computers
    By Tyger0951 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-24-2014, 06:36 AM
  7. How can I ensure a workable code among different computers?
    By lubbamkt in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-16-2014, 10:05 PM

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