Solved

renaming files using vb code

Posted on 2001-06-06
4
133 Views
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.
eg.
Dim strFileName As String

With frmAssessment.dlgImage
    .FileName = ""
    .ShowOpen
End With

strFileName = frmAssessment.dlgImage.FileName

Now how can I change the name of the file. Any other ideas.
0
Comment
Question by:Yakeni
  • 2
4 Comments
 
LVL 142

Expert Comment

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

Cheers
0
 
LVL 6

Expert Comment

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

Accepted Solution

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

Author Comment

by:Yakeni
ID: 6162647
That was simple wasnt it
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) 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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now