Solved

Remove dot and filename extension

Posted on 2013-12-01
6
159 Views
Last Modified: 2014-02-07
Below is the macro:
Sub DuplicateRename()
    strFileCopyFrom = ThisWorkbook.Path & "\" & Sheets("Sheet1").Range("C3").Value
For Each c In Range(Range("A2"), Range("A" & Cells.Rows.Count).End(xlUp))
    strFileCopyTo = ThisWorkbook.Path & "\" & Sheets("Sheet1").Range("C3").Value & "_" & Format(c, "000") & ".pdf"
    FileCopy strFileCopyFrom, strFileCopyTo
Next
End Sub

Example:

Original name: Maintenance Check Form.pdf

What the Macro creates:
Maintenance Check Form.PDF_SA1563HJ.pdf
Maintenance Check Form.PDF_SA1564HJ.pdf

Need to delete the ".pdf" in the ~center of file name or delete the four characters to left of the underscore ( _ )

The deleting of characters, I would guess, is more encompassing whereas deleting the .pdf would only apply to pdf files

Thanks
0
Comment
Question by:dgd1212
  • 3
  • 3
6 Comments
 
LVL 20

Expert Comment

by:CompProbSolv
ID: 39689084
One method is to change:
    strFileCopyFrom = ThisWorkbook.Path & "\" & Sheets("Sheet1").Range("C3").Value
For Each c In Range(Range("A2"), Range("A" & Cells.Rows.Count).End(xlUp))
    strFileCopyTo = ThisWorkbook.Path & "\" & Sheets("Sheet1").Range("C3").Value & "_" & Format(c, "000") & ".pdf"

to:
    strFileCopyFrom = ThisWorkbook.Path & "\" & Sheets("Sheet1").Range("C3").Value
d=left(strFileCopyFrom,len(strFileCopyFrom)-4)

For Each c In Range(Range("A2"), Range("A" & Cells.Rows.Count).End(xlUp))
    strFileCopyTo = d & "_" & Format(c, "000") & ".pdf"


The added line that creates d will strip off the trailing 4 digits.  The shortened version will get used to create strFileCopyTo
0
 

Author Comment

by:dgd1212
ID: 39689558
Tried suggestions but no results.

Just to clarify:
What the Macro creates:
Maintenance Check Form.PDF_SA1563HJ.pdf
Maintenance Check Form.PDF_SA1564HJ.pdf

What the result should be:
Maintenance Check Form_SA1563HJ.pdf
Maintenance Check Form_SA1564HJ.pdf

The trailing 4 digits must be kept

Thanks
0
 
LVL 20

Expert Comment

by:CompProbSolv
ID: 39690461
What results did you get with the suggestion?

The trailing 4 digits that I was trying to remove should have come from Maintenance Check Form.PDF in the strFileCopyTo

Make sure you include the second change which is in the last line.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:dgd1212
ID: 39691595
Below is the macro:
Sub DuplicateRename()
    strFileCopyFrom = ThisWorkbook.Path & "\" & Sheets("Sheet1").Range("C3").Value
d = Left(strFileCopyFrom, Len(strFileCopyFrom) - 4)

For Each c In Range(Range("A2"), Range("A" & Cells.Rows.Count).End(xlUp))
    strFileCopyTo = d & "_" & Format(c, "000") & ".pdf"
    Next
End Sub

When I run there is no created files in the directory. See attached.

Probably something obvious i'm missing....

Thanks
InstallForms.xlsm
0
 
LVL 20

Accepted Solution

by:
CompProbSolv earned 500 total points
ID: 39693227
My post did not include everything.  It appears that you have left off the following before "Next":
    FileCopy strFileCopyFrom, strFileCopyTo
0
 

Author Closing Comment

by:dgd1212
ID: 39843405
Finally got it to work. Sorry for the delay.
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Auto Populate Day Month  2 digit Date 4 19
Excel VBA User Form Help 21 29
Unhide very hidden sheets with password 22 44
Request to review costing formula 3 35
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question