+ Reply to Thread
Results 1 to 20 of 20

Script works but skips files in defined range.

  1. #1
    Registered User
    Join Date
    03-19-2015
    Location
    Austin, Texas
    MS-Off Ver
    2013
    Posts
    21

    Script works but skips files in defined range.

    Hello.

    I need help with this bit of VBA. The script executes successfully but it skips some files about 259 out of 350 are getting copied. All links have been validated and work.

    Any feedback will be much appreciated.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,298

    Re: Script works but skips files in defined range.

    Do you have any files with the same names, but in different folders? Check for existence before copying, and if they exist, then create a unique name

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Script works but skips files in defined range.

    I'm not sure wht the problem is. Bernie's suggestion sounds plausible. Also consider duplicate hyperlinks within the Range? I would suspect the issue is with the Hyperlinks, the Range, or the files, and not so much with the VBA code itself.

    On another note, you can loop through the hyperlinks within your visible range using the hyperlinks collection...

    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 04-01-2016 at 12:44 PM.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Registered User
    Join Date
    03-19-2015
    Location
    Austin, Texas
    MS-Off Ver
    2013
    Posts
    21

    Re: Script works but skips files in defined range.

    Ok it brings in the right number of files now however it is duplicating pdfs for some reason. I have verified that each hyperlink is unique and the file names in the source locations are unique from each other.

    Example below is a list that i tested this on. Originally my script would only bring in the first pdf in the list. Now with Bernies updated script it looks at all the instances but duplicates the first PDF and

    Sources its looking at.

    ..\..\..\..\Cutsheets\Delta\Software\01 - Controller - Delta - DOW-340-HL.pdf
    ..\..\..\..\Cutsheets\Delta\Software\01 - Controller - Delta - DOW-340-HL-I.pdf
    ..\..\..\..\Cutsheets\Delta\Software\01 - Controller - Delta - DOW-340-HM.pdf
    ..\..\..\..\Cutsheets\Delta\Software\01 - Controller - Delta - DOW-340-HM-I.pdf
    ..\..\..\..\Cutsheets\Delta\Software\01 - Controller - Delta - DOW-340-HS.pdf
    ..\..\..\..\Cutsheets\Delta\Software\01 - Controller - Delta - DOW-340-HS-I.pdf


    What it pastes in folder. It uses same pdf and adds the row number to beginning. Its like its not reading the Characters in the hyperlinks past the HL.

    01 - Controller - Delta - DOW-340-HL.pdf
    36-01 - Controller - Delta - DOW-340-HL.pdf
    37-01 - Controller - Delta - DOW-340-HL.pdf
    38-01 - Controller - Delta - DOW-340-HL.pdf
    39-01 - Controller - Delta - DOW-340-HL.pdf
    40-01 - Controller - Delta - DOW-340-HL.pdf

  5. #5
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,298

    Re: Script works but skips files in defined range.

    I am guessing that you copied your hyperlinks and changed the display string but not the actual file address. Look in cells L36, 37, 38, 39, and 40.

    Otherwise, there are errors and the .Address value is somehow not being properly updated from those cells.

    What does this show?

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    03-19-2015
    Location
    Austin, Texas
    MS-Off Ver
    2013
    Posts
    21

    Re: Script works but skips files in defined range.

    So when I run your error check it brings back this.

    ..\..\..\..\Cutsheets\Delta\Software\01 - Controller - Delta - DOW-340-HL.pdf
    ..\..\..\..\Cutsheets\Delta\Software\01 - Controller - Delta - DOW-340-HL.pdf

    but when i click on the link it takes me to the right file and then also when i go into edit hyper link it gives me this as the address for each


    ..\..\..\..\Cutsheets\Delta\Software\01%20-%20Controller%20-%20Delta%20-%20DOW-340-HL-I.pdf
    ..\..\..\..\Cutsheets\Delta\Software\01%20-%20Controller%20-%20Delta%20-%20DOW-340-HM.pdf

  7. #7
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,298

    Re: Script works but skips files in defined range.

    How about?

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    03-19-2015
    Location
    Austin, Texas
    MS-Off Ver
    2013
    Posts
    21

    Re: Script works but skips files in defined range.

    Gives back
    2
    2

  9. #9
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,298

    Re: Script works but skips files in defined range.

    I think that having more than 1 hyperlink in a cell is the source of your error - you are always assuming Hyperlink(1) is correct (and I honestly don't know how to add two hyperlinks to one cell....)

    Please Login or Register  to view this content.
    Maybe it can all be fixed if you change
    Please Login or Register  to view this content.
    to


    Please Login or Register  to view this content.
    Last edited by Bernie Deitrick; 04-01-2016 at 04:51 PM.

  10. #10
    Registered User
    Join Date
    03-19-2015
    Location
    Austin, Texas
    MS-Off Ver
    2013
    Posts
    21

    Re: Script works but skips files in defined range.

    This worked out. And yes running the new FindError script did reveal multiple associated hyperlinks.

    How is that possible? I can not find where the extra links exist. I assume it may be from the original document creator copying and pasting.

    What can I do in the future to avoid this?

  11. #11
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,298

    Re: Script works but skips files in defined range.

    Try running this to clean out the extra HLs: I have assumed that later HLs are the desired HLs.

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    03-19-2015
    Location
    Austin, Texas
    MS-Off Ver
    2013
    Posts
    21

    Re: Script works but skips files in defined range.

    Great thanks

    So know I have modified the code to create a Dir and then put the files in that Dir.

    It worked initially multiple times and tests runs with no issues but once it was saved down, closed, and reoppened it errors out on file path not found for the Mkdir command.

    To help I am running this off a Networked drive.

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    03-19-2015
    Location
    Austin, Texas
    MS-Off Ver
    2013
    Posts
    21

    Re: Script works but skips files in defined range.

    Great thanks

    So now I have modified the code to create a Dir and then put the files in that Dir.

    It worked initially multiple times and tests runs with no issues but once it was saved down, closed, and reoppened it errors out on file path not found for the Mkdir command.

    To help I am running this off a Networked drive.

    Please Login or Register  to view this content.

  14. #14
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,298

    Re: Script works but skips files in defined range.

    Is the error because the folder exists?

    Please Login or Register  to view this content.
    Or that the network folder is not the default drive? Then, the ..\ will not work - not sure what your network drive is named....

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    03-19-2015
    Location
    Austin, Texas
    MS-Off Ver
    2013
    Posts
    21

    Re: Script works but skips files in defined range.

    The folder does not exist. I did try the If statement method prior to posting and got same error.

    What has been discovered is when ?CurDir is run in Immediate window my local drive pops up... Is there a way to get excel to recognize the path from which it was launched?

    Also the current network drive letter is Y:

    C:\Users\steve\Documents

  16. #16
    Registered User
    Join Date
    03-19-2015
    Location
    Austin, Texas
    MS-Off Ver
    2013
    Posts
    21

    Re: Script works but skips files in defined range.

    Figured it out

    Please Login or Register  to view this content.

  17. #17
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,298

    Re: Script works but skips files in defined range.

    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    03-19-2015
    Location
    Austin, Texas
    MS-Off Ver
    2013
    Posts
    21

    Re: Script works but skips files in defined range.

    Ok so everything is working greqat now except when I save and close out now the hyperlin address path errors out. However if I click the hyperlinks and navigate to the document manually and then run script again it all updates successfully and runs.

    Any idea what could be causing that?

  19. #19
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,298

    Re: Script works but skips files in defined range.

    I think that it is the ..\ part of the file path. You either need to set an absolute path "Y:\folder...." or change to the correct directory tree when the file is opened. You could use

    Private Sub Workbook_Open()
    ChDrive "Y:\"
    End Sub

    In the codemodule of the ThisWorkbook object.

  20. #20
    Registered User
    Join Date
    03-19-2015
    Location
    Austin, Texas
    MS-Off Ver
    2013
    Posts
    21

    Re: Script works but skips files in defined range.

    Ok so below is the original code and now it calls a new Sub that takes pdfs from one location based on a visible cell range and then put them in the directory and then calls another module to merge the pdfs. In the second module there is a variable strPath that when the full folder path is defined it works fine. However trying to use a structure like "..\Submittal Packaged\BOM PDF\" it gets stuck in the while loop. I have debugged and watched it step through and find every pdf file in the folder but instead of not seeing the end it loops back to the beginning.

    The below code is configured in the way I am having issues.

    Please Login or Register  to view this content.

+ 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. Replies: 1
    Last Post: 08-25-2015, 05:40 PM
  2. Macro for inserting rows w/ data works fine for 4iterations, but skips updates in 5th
    By koushik_s in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-15-2015, 10:45 AM
  3. Script skips past numbers in an array.
    By Kalzin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-27-2015, 04:16 PM
  4. [SOLVED] If word entered not in defined name range, copy & paste it to bottom of defined name range
    By Butcher1 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-09-2014, 01:08 PM
  5. Script works on XP but not on Win4
    By nironto in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-03-2012, 04:56 AM
  6. Opening files from defined range
    By andrea_1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-28-2009, 06:44 PM
  7. Range.Find skips the first cell ??
    By slintz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-14-2005, 08:05 PM

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