+ Reply to Thread
Results 1 to 11 of 11

Renaming File from "Scan.pdf" to Target Cell Text, Debug Error.

  1. #1
    Forum Contributor
    Join Date
    05-03-2021
    Location
    Nashville
    MS-Off Ver
    MS Office 365
    Posts
    189

    Renaming File from "Scan.pdf" to Target Cell Text, Debug Error.

    All,
    I am trying to automate a renaming of files that get scanned to a specific folder.

    The code that works with no errors is
    Please Login or Register  to view this content.
    The problem is I need the file to get renamed into a folder called "PDF" where "ThisWorkbook" resides.

    The code I WANT to use so when the file name gets renamed, it STAYS in the folder "PDF" but if I add a "PDF" subfolder it gives a Debug error.

    Please Login or Register  to view this content.
    I know I'm probably missing a step or have not formatting it just right. If push comes to shove I can always keep it in my "Documents" folder but am trying to automate this so it is easy for folks to find the file quickly rather than combing through hundreds of files in "Documents".

    TL;DR;
    ThisWorkbook is in a subfolder called "PDF"
    I run macro and the file gets moved out of PDF into a folder called Documents.

    I tried added a "PDF" sub folder in the code and throws an error.
    Attached Files Attached Files
    Last edited by thenewkidd; 02-13-2023 at 10:33 PM. Reason: Work around.

  2. #2
    Valued Forum Contributor
    Join Date
    11-26-2012
    Location
    Sydney
    MS-Off Ver
    2010
    Posts
    423

    Re: Renaming File from "Scan.pdf" to Target Cell Text, Debug Error.

    Looks ok to me, apart from a typo - try changing 'Targe_Folder' to 'Target_Folder'.

    To avoid this type of thing, it's good practice to include 'Option Explicit' to the top of each Module (you can have this happen automatically by going to Tools - Options - Require Variable Declaration).

  3. #3
    Forum Contributor
    Join Date
    05-03-2021
    Location
    Nashville
    MS-Off Ver
    MS Office 365
    Posts
    189

    Re: Renaming File from "Scan.pdf" to Target Cell Text, Debug Error.

    Thank you for trying to help, it is much appreciated.

    Though that was a typo AND it was found in the code, I fixed that typo and it still gave the same error.

    Screen shot below.
    Attached Images Attached Images

  4. #4
    Forum Contributor
    Join Date
    05-03-2021
    Location
    Nashville
    MS-Off Ver
    MS Office 365
    Posts
    189

    Re: Renaming File from "Scan.pdf" to Target Cell Text, Debug Error.

    Though it says file not found, the file exists AND it is in the folder. Like I said, I take "PDF" out of the code and say
    Please Login or Register  to view this content.
    it works I don't know why adding & "PDF" after doesn't allow it to work when I can clearly see the folder where "This workbook" resides!

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Renaming File from "Scan.pdf" to Target Cell Text, Debug Error.


    Hi,

    that just obviously means a path or even the source filename does not exist ! So just check the strings …

  6. #6
    Forum Contributor
    Join Date
    05-03-2021
    Location
    Nashville
    MS-Off Ver
    MS Office 365
    Posts
    189

    Re: Renaming File from "Scan.pdf" to Target Cell Text, Debug Error.

    The file exists.

    While it is incredibly annoying. ThisWorkbook.Path & "\PDF" should = "C:\Users\spratt\Documents\PDF"
    If I use ThisWorkbook.Path it throws an error while C:\Users\spratt\Documents\PDF\ does not is the stupidest thing I have ever seen.
    Don't worry, I'm young so there's still time for a new stupid thing. lol

    I don't know how the file doesn't exist with "ThisWorkbook.Path" but it does exist when I the spelled out file location explicitly.
    If the file didn't exist, It would give in error in both instances, correct? I mean I could be wrong, I'm pretty new at VBA so it is entirely possible. I am making this for a team of people at work so they will not be able to use MY directory

    At any rate... Instead of trying to understand what is wrong, I will just do a work around.
    In Cell L1
    =LEFT(CELL("filename",C1),SEARCH("[",CELL("filename",C1))-1)
    Then I just made Target_Folder = Sheets("RENAME PROGRAM").Range("L1").Text

    Now it works like a charm. I shouldn't have had to do that and I agree there was probably something I did wrong, but here we are. Apparently "ThisWorkbook.Path" in the subfolder PDF does not equal C:\Users\spratt\Documents\PDF\

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Renaming File from "Scan.pdf" to Target Cell Text, Debug Error.


    As I wrote, the file does not extst in the given path … So just check the source path as it can't be obviously the destination / target path !
    As a reminder : Name Source as Destination …

  8. #8
    Forum Contributor
    Join Date
    05-03-2021
    Location
    Nashville
    MS-Off Ver
    MS Office 365
    Posts
    189

    Re: Renaming File from "Scan.pdf" to Target Cell Text, Debug Error.

    There is nothing to check. Everything is defined.
    Target_Folder is the Destination. It is defined. If it wasn't, it would give an error even if hard coded
    The source path is ThisWorkbook.Path & "\PDF\."
    In that subfolder there is a PDF named "Scan.pdf".
    So the file exists EVEN THOUGH the error says it doesn't. I gave the source code I had written. So unless "ThisWorkbook.Path & "\PDF\." does NOT equal C:\Users\spratt\Documents\PDF\ I don't know what else there is to check.


    This is like saying a + b = 4 and a = 1 and b = 3 and it the error given is saying "number cannot be found".
    So I hard code the 1 + 3 = 4 and no error or use the variables and there is an error makes literally no sense.

    So unless I am misunderstanding the variable "ThisWorkbook.Path" and how that works. The question is not whether the file exists, it is WHY putting C:\Users\spratt\Documents\PDF\
    works while ThisWorkbook.Path & "\PDF\." does not.

    The picture Shows the file exists and it IS called "Scan.pdf"

    Again, thank you for trying to help. But at this point unless someone can actually point out where my logic is wrong, just saying "the file doesn't exist, check the Strings" will not resolve anything as those have been checked and double checked.
    Attached Images Attached Images
    Last edited by thenewkidd; 02-14-2023 at 02:56 AM.

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Try this ...


    When the logic fails this error rises …

    According to your logic a VBA demonstration which displays a message when the source file is not found
    and if an error rises on the Name codeline so something is wrong in cell C1 or according to VBA help the destination file already exists :

    PHP Code: 
    Sub Test4Noob()
        
    Dim S$
            
    ThisWorkbook.Path "\PDF\Scan.pdf"
        
    If Dir(S) = "" Then
            MsgBox S 
    vbLf vbLf "File not found !"16"Error"
        
    Else
            
    Name S As ThisWorkbook.Path "\" & ['RENAME PROGRAM'!C1].Text & ".pdf"
        End If
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 02-14-2023 at 06:02 AM.

  10. #10
    Forum Contributor
    Join Date
    05-03-2021
    Location
    Nashville
    MS-Off Ver
    MS Office 365
    Posts
    189

    Re: Renaming File from "Scan.pdf" to Target Cell Text, Debug Error.

    I 100% agree. I wouldn't have reached out if I thought it was just a simple double check and everything was good.
    This is why I'm a huge fan of peer review, other see things that are blind to the creator.
    Thank you for the noob code I fear I will forever be a noob when it comes to VBA.

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Renaming File from "Scan.pdf" to Target Cell Text, Debug Error.


    Well, you misread …

+ 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] Why I get "Object required" debug error (Beginner level)
    By rcurious in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-14-2021, 02:23 AM
  2. Replies: 11
    Last Post: 08-05-2020, 10:10 AM
  3. [SOLVED] Help to Debug error "Can't perform requested operation"
    By Andrew Entee in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-03-2019, 09:43 AM
  4. Replies: 4
    Last Post: 03-11-2016, 03:34 PM
  5. "Worksheet change" not changing cell on other sheet to match target cell "fill".
    By Ochimus in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-02-2015, 12:02 PM
  6. Excel 2010 (Run-time error '13' type mismatch) "Debug" and "Continue" Grayed out.
    By Jeronimo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-18-2012, 06:42 PM
  7. Transfert cell values from file "A" to file "B" skipping columns in file "B".
    By Sentrosi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-16-2009, 11:11 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