renaming files using vb code

Posted on 2001-06-06
Last Modified: 2010-05-02
Dim strOldFilename as string
Dim strNewFileName as string

'now just say strNewFileName = P1S1P1

'the original filename is image1.jpj
'this file is stored in C:\database\images\
we want image.jpj to change to p1s1p1.jpg now how would I go about this using vb code. I have used a common dialog box used to select the file. eg image1.jpg.

The location of the filename can be stored in a variable.
Dim strFileName As String

With frmAssessment.dlgImage
    .FileName = ""
End With

strFileName = frmAssessment.dlgImage.FileName

Now how can I change the name of the file. Any other ideas.
Question by:Yakeni
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6162621
NAME strOldFileName AS strNewFileName


Expert Comment

ID: 6162622
Public Sub RenameFile(ByVal strFilename As String, _
  ByVal strNewFilename As String)
  On Error GoTo PROC_ERR
  Name strFilename As strNewFilename
  Exit Sub
  MsgBox "Error: " & Err.Number & vbCrLf & _
         "Description: " & Err.Description, vbCritical
  Resume PROC_EXIT
End Sub

Accepted Solution

sharmon earned 50 total points
ID: 6162623
just can seem to hit the button fast enough:)

Author Comment

ID: 6162647
That was simple wasnt it

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month7 days, 21 hours left to enroll

617 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