Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

Copying And Renaming A Form In Vb6

Occasionally, I need to make a copy of an existing form and add it to the same vb6 project. It never seems to work because the form always remembers its original name and the project gives me an error message that says " a form of that name already exists". Can someone please tell me how to accomplish this task. In this case I have a form that contains 75-80 percent of what I need.

View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Copying/Renaming Files Uploaded Using A Form And Script
I've made a Software Estimate Tracking program where a user inputs a description, title, etc. of an estimate and then uploads a file onto a server. I've been using an Access 97 database, a Web page Form, and a VB script to proccess the data. I'm coding the script in VB 6.0. Now I have it where the user uploads a file to be store in a string variable "UploadedFile."
Here was my following test code:

UploadedFile = "temp.txt"
FileCopy UploadedFile, "SWEFiles/test.txt"

The directory I set it to was at the beginning of my program:

ChDir ("app-swSWestimates")

So I'm basically copying files in that Network Neighborhood directory. Now as you can see by the code, I have it working If I set pre-defined paths for the source and destination of the FileCopy method. But, I wanted it so that the Source is equal to whatever the user picks as the file. And I wanted that file copied, renamed, and then stored on the server. If I can't do this with FileCopy, is there some other way of coding it?
Thanks for reading my post... =)

Copying And Renaming A File On The Fly?!
I would like to copy a file (using a common dialog) from a source, and save it to my destination and rename the file at the same time.
They should be an easy way, no?

Copying AND Renaming Worksheets
I am trying to copy a 'template' worksheet and rename it as 'Region', making the new copy ready for use.

I am currently using:
Worksheets("Template").Copy after:=Worksheets("Template")

but this simply produces a copy named Template (2).

Is there any way of copying the sheet AND renaming it without having to add a blank sheet custom named and then pasting in the desired contents? Better yet is there any way or naming the new/copied sheet with a value from a cell?


Copying And Renaming VB Script Easy For You
Hi Everyone -

I need to preform a daily backup of a file by copying an .mdb from one location (Location = C:Program FilesPARKINVT) renaming it by including the hostname(name of the machine),date and time in the field name (Ex File Name = PARK_INVT.mdb should be copied to,

and upload it to a FTP server Can some one help me on this?

I am a *nix guy from my childhood, i dont know VBS much..i already took care of the uploading part but i just need to rename and copy the files to the directory from which i will be uploading..

Thanks In Advance!

Renaming And Copying New File To Current Project Path
hello guys!

i hope that you can help me with this... i created a picture viewer wherein i used drive1... dir1... and file1. my problem is... how can i change their filename? like for example... i have cute.jpg on my documents folder... i want it to be renamed as 0001.jpg and transfer that to my app.path program. how can i do that?

hope you can help me with this... thanks in advance

Helpz Guyz. Copying,renaming File [unresolve]
currently i am using this code below. it';s working. but i want to copy not move.

VB Code:
sSrcPath = dirSrc.path & "" & fileSrc.FileNamesDtnPath = dirDtn.path & "Database_backup_" & Day(Date) & "-" & Month(Date) & "-" & Year(Date) & ".txt"  '.mdb Name sSrcPath As sDtnPath


i've tried some of these but not working

VB Code:
Move sSrcPath to c:Move "test.txt to "ackup esting.txt"rename "c:" & fileSrc.Filename to "c:" & "Database_backup_" & Day(Date) & "-" & Month(Date) & "-" & Year(Date) & ".txt"  '.mdb

it highlighted the "to" in the code and display a msgbox "espected : end of statement"

using "copy" might not be correct but "move" does work too.

VB Code:
Dim fso as string Set fso = CreateObject("Scripting.FileSystemObject") fso.CopyFile "C:Phone_Log_Reports*.xls", "C:Phone_Log_ReportsHistory"fso.DeleteFile "C:Phone_Log_Reports*.xls"

it stops at "set fso = createob....." and msgbox says "object required"

code taken from :

and more Q, should it be
App.Path & "..." or App.Path + "..." ..
i saw some e.g. uses " + " and if i am not wrong, " + " is used in java

Copying And Renaming A File With The Date/time In The Filename
Hi there,

I've never done much with VB as far as moving files aroudn and such and am hoping someone cna whip me up what I think wuld be a very simple little program.

All it would do would be every hour, take a file from a particular folder, copy it to a different folder, and rename it and add the date/time onto the filename somehow.
So a file called Database.mdb would get changed to database 031420021100 for March 14th, 2002 at 11:00. It doesn't have to be that format, just an example.

Can someone give me the couple lines I'm guessing it would take to do that?


Renaming A Form
Here is my problem im trying to rename a form with this: = formx

but it gives me this:
Compile error: Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic

And it wont even change the name of the form does anybody know why?

Copying A Form
Is it possible to use an existing form as a template for another form? I tried copying a form in my directory and then renaming it, but I couldn't add it to my project because "it had the same name" - am I missing something?

Copying From 1 Form To Another
is their any way of checkin whether info on 2 different forms can be checked to see whether or not they actually match.
if any1 can help i'd much appreciate it

thanx people

email add;

Copying A Form
Copying the code that is behind a form is no problem when using the clipboard.
Copying the commands, text boxes and so on is also simple.

But is there a possibility to copy the form itself, including the properties I have given it?
Right now, when I want to have two forms that look almost exactly the same, I make a new form, change the properties the way they should be, paste in the controls and the code. There must be a simpler way of doing this.

Thanks on beforehand for any advice.

Copying A Form??
I have created a form that I want to use as my template for other forms, can this be done in the same project??


Copying Controls From One Form To An Other
How is it possible to copy controls (TextBox, CheckBox, CommandButton, etc.) from one form and paste it to an other one.
This has to be done by code in VBA Excel.
I know how to copy the code behinde the control but I can not copy the object with its appearance....

Thanks in advance.....

Copying Form && Controls
User to be allowed to copy a form & controls on it. I tried by NewForm1 method but the new form's name is same i.e. Form1 & controls name too same as from1's control names. Since I need to refer in common module for each forms' controls, it become impossible. e.g. I have text1 control on Form1 & when I copy form (at runtime), new form's name is Form1 & textbox name is text1. Then how do I refer to textbox of old form & textbox of new form?

Copying A Frame From One Form To Another
using code executed on a command1_Click

Is there a clean way of doing this?


Copying A Form From One Project To Another

is there a way i could copy a form from one project to another but just the form, its buttons, combo boxes and its list boxes and not the code?

Copying And Pasting A Form
is there a quick way of copying and pasting a whole form (including code within the form load) to another form, without needing to select every element of that form.

Thanks for any assistance.

Copying Form Contents
Hi all..
I have this particular problem. I have a form with some plotting
done on that. Now, I was wondering if I could copy the whole
drawing/plotting of that form onto a different form & then do some
other plotting on the first form afresh. Is there any way to do this?
I would be thankful for any ideas or suggestions. Thanks in advance.


Copying Listviewitems To Another Listview(another Form)
hi guys, I am trying to copy the items on my first listview(from form1) to the second listview(form 2)

I having some problem doing this, and I don't know what I've been doing wrong..

right now I'm using this code

vb Code:
X = 1For N = 0 To Me.lvwOutPerif.ListItems.Count - 1Set lstItem = frmDataEntry.lvwHistoryPerif.ListItems.Add (, ,Me.lvwOutPerif.ListItems(X)                                                                                                 lstItem.SubItems(1) = Me.lvwOutPerif.ListItems(X).ListSubItems(1).Text 'Error occurs here saying that says invalid property value X = X + 1Next N

Copying A Form And Putting It In Your Project???
Is there there away to copy a form completely change its name and then add it to your project without making a newform, setting up the form properties, and pasting in the code and objects???????

Copying Forms, Or Using A Form As A Template
To create a new Form2 from form1

a) Save Form1 as Form1
b) Rename Form1 as Form2
c) Save Form2 as Form2
d) add Form1 back into the application

Copying A Specific Image Into A Form.
Does anyone know how to copy a specific window into a form by using "Bitblt"? If I have a handle to a specific window, how do I copy it into my form? Whether if it is minimized or maximized.

Another question, is the only way possible to load an image file is using "LoadPicture". Can I use sometype of API to tell VB where the image file is located and load it in?

If you help me, I will give you a penny, just kidding.

Copying Data From Access Form Into Excel
I'm new to VBA, and I need to write a function that will
copy the records from a form, open an excel spreadsheet,
and copy the data into particular cells. The code below
does exactly what I want it to do, but only once. If I
try to run the code again without restarting the data
base, I get an error that says, "Object variable or with
block variable not set." If anyone can help me I would
really appreciate it.

Private Sub Command17_Click()
On Error GoTo Err_Command17_Click

Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "PasswordAssess"
'Open form and copy records
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.RunCommand acCmdSelectAllRecords
DoCmd.RunCommand acCmdCopy

'open excel application
Set xlApp = New Excel.Application
'Open excel workbook
Set xlWB = xlApp.Workbooks.Open
(Filename:="C: est.xls")

ActiveSheet.Paste Destination:=Worksheets("Accounts &

'Close workbook (optional)
'Quit excel (automatically closes all workbooks)
'Clean up memory (you must do this)
'Set xlWB = Nothing
'Set xlApp = Nothing

'Close form
DoCmd.RunCommand acCmdClose

Exit Sub

'Close workbook (optional)
'Quit excel (automatically closes all workbooks)
'Clean up memory (you must do this)
Set xlWB = Nothing
Set xlApp = Nothing
DoCmd.RunCommand acCmdClose
MsgBox Err.Description
Resume Exit_Command17_Click

End Sub

Copying Data From A Listview Row To A Textbox In Another Form
To illustrate well, I have provided the following screenshots.

What I want to happen is, from this form

When I click on a particular record/row, then click the View button, another form should appear, like this

containing the same data as in the listview, placed on the corresponding fields, of course.

Now, I can do this only for the first record/row in my listview. How do I do it for all of them so that when I click on the next record, say matt's record, the Feedback Details form will indicate the details of matt's record?

Creating, And Copying Data From A Form Into A Database
I have recently created a form that picks up a total (count) from a link program from another application. The count on the records is then displayed in a text box, that is visible by the user.
If the count exceeds a cetain level a warning is displayed and an warming sound is activated.
What I would also like to add is database. I would like to creat a function on a button, so as when the button is clicked, the current totals are copied to a Microsoft Access database. I would like the database to store the total count, and also add a time and date stamp to the totals at the time the form was closed.
I am fairly new to this side of VB and any assistance would be much appreciated.


Copying Data From Other Apps Into Excel Form (textbox) Automatically
hi all,
is it possible to copy data from a completely different running application into an excel form automatically ?

Help With Renaming
Can someone tell me a way to rename a registry key please?

Help Renaming
I know a few ways to complete the code, but what I need is a way to get a list of a directory and subdirectories, with the files. What I want to do is rename every file, making strOld as the old name, and strNew = Replace(strOld, "_", " ")
to remove to _'s in my mp3 file names!

I want to point to a folder, and rename all the files in there at once. Is this possible?

Renaming Mdb
here's a question...

for aesthetic/security/whatever purposes, i was going to change the extension of my database file to tbc named after the application. could i still access it without a problem???

I need to know the code so i can rename a file. Im not very good at visual basic but heres what i want:
I have 6 files, and 6 command buttons. I want to be able to click on eg command button 3 and have 3.cfg renamed to default.cfg

Thanks for the help.

Is there a way for me to Rename or Create a FOLDER on a drive.

I'm copying an entire user profile to a network drive. In this process i get path errors because the folders either don't exist or have different names. A create command would be better, but if it comes down to it i would settle for renaming it.
Any ideas would be appreciated.


Copying A Listview Object? (More Generally, Copying Any Object To Another)
Hey all. My searches didn't really clear anything up for me, so I thought I'd ask my question specifically:

I have a form with a listview the user can populate. Once done, they can clear it. I need to have a recall feature that would allow them to basically undo the clear. My initial thought is to copy the form's listview to a listview object declared dynamically. However, this statement I think just creates a reference to the forms listview: Set DynamicListView = FormListView. So, when I clear the FormListView, of course the DynamicListView clears too, since its just pointing to the same view.

How do I dynamically create one listview from one on the form?


Renaming And Application

I have an application called...ehm....."WindowsApplication2" which I'd like to rename. Preferably without having to rebuild it, as I had to do this once already (and forgot to change the name to something suitable) and it was a pain to do.

Is there an easy way to do this?


Renaming Folder
I have a p^roblem qith the Name statement... it just get me an error 75 everytime i execute that... it may just be a stupid error But i cant see it... help please!!!!

Dim oldpath As String
Dim newpath As String
oldpath = App.Path & "data" & mstrNom
newpath = App.Path & "data" & txtNom.Text
Name oldpath As newpath

Renaming Folders
Here's the basic idea of my problem:

I have a large number of folders located together within the same main folder. Each folder is named as a ten-digit number, such as "0123456789." I need to go through every folder and rename it so that the name would now appear as "012-3456-789." I know enough about string manipulation that I could easily add the dashes to the name. However, I don't know what command I would use to rename the folders. Also, because I need to rename every folder, I need to know how I would loop through every folder that is located within main folder.

Renaming Folders..
I know this is VBS related, but I'm not using it for web programming..

I am using the script below and need it to rename folders instead of files. It basically reads names.txt which contains:


and so on..

I tried chaging strFile to strFolder, but no luck, it runs and no folders are renamed.

I also need it to use the current dir/folder but there again no clue.

Can someone please help?

PHP Code:

Const ForReading = 1

strComputer = "."
set objWMIService = GetObject("winmgmts:\" & strComputer & "

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:Documents and SettingsMy Name Is MudMy DocumentsLost Treasures
ames.txt", ForReading)

Do Until objFile.AtEndOfStream
    strLine = objFile.ReadLine
    arrParts = Split(strLine, ",")
    strFolder = "C:\Documents and Settings\My Name Is Mud\My Documents\Lost Treasures\Test\" & arrParts(0)
    Set colItems  = objWMIService.ExecQuery _
        ("Select * From CIM_Datafile Where Name = '" & strFolder & "'")
    For Each objItem in colItems
        strNewName = "C:Documents and SettingsMy Name Is MudMy DocumentsLost TreasuresTest" & arrParts(1)
        objItem.Rename strNewName


REnaming Files

Im trying to make a programthat allows people to rename files (any type not only .txt.. including .html, .exe and etc.)

what is the syntax to rename?

Renaming A Log File
I need to rename a log file which has the path of:




I have looked around and found many examples and disucssions of just this but unfortunatley have not been able to understand them.

Any help appriciated.

Renaming Files
O.k. this should be simple, but I am a novice VB programmer at best. I have 3 files that I simply need to rename. I have a user that cannot copy and paste a file and then rename it(I know, sounds stupid, but it's what I have to deal with), so I'm trying to just give her a button to click on to do it for her. Below is the code I have. The problem is that nothing happens when I click the button. I'm pretty sure the Name function I've got is correct, but I could be wrong.

Private Sub Rename_Files_Click()
Dim x As Integer

x = 1

Do While x < 2

Name "CTestxxx_12345678_20050725.txt" As "P:Test2
Name "CTestxxx_98756321_20050725.txt" As "P:Test2
Name "CTestxxx_36587412_20050725.txt" As "P:Test2

x = 2


End Sub

Also, notice that the last set of numbers in the original filename is a date stamp. How can I have the files get renamed regardless of what the date stamp is? Can I use any kind of 'wildcard' character in its place? ex "CTestxxx_12345678_*.txt" Any help would be appreciated!!

Renaming A File
First a little background:

I have a macro in word which prompts the user for a file name. The file contains data which will be imported and placed in bookmarks within the document.

Because of the way the application works, all the data files are in a common area (this is the way it has to be). This does mean however that more than one user can select the same data file at the same time. The data file is read only so this, in itself is not a problem but it does cause other problems further down the macro.

What I want to be able to do is:

When the first user selects a data file, rename it temporarily until they have finished with it and then, on exit from Word, rename it back.

Below is a cut-down version of the code I have at the moment.

Dim vrtSelectedItem As String
Dim vrtSelectedItemUse As String
Dim oFSO As FileSystemObject

CurrentDir = Left(ActiveDocument.AttachedTemplate.Path, 3)

fd = InputBox("Please Enter the Unison Quote No.", "Enter Quote Number")

If fd = "" Then AllDone

vrtSelectedItem = CurrentDir & "data" & fd & ".txt"

Set oFSO = New FileSystemObject

If Not oFSO.FileExists(vrtSelectedItem) Then
MsgBox ("The file " & fd & ".txt does not exist")
vrtSelectedItemUse = CurrentDir & "data" & fd & ".use"
' I know I need something here but I'm not sure what
End If

I have two questions:

1. What code do I need above in the "I know I need something here..." section to rename the file vrtSelectedItem to vrtSelectedItemUse?

2. How do I trap the fact that the user is exiting Word so that I can perform the rename the other way round?

I hope this is clear enough and that someone out there can point me in the correct direction.

Renaming Worksheets

I'm trying to rename my worksheets.
If you look at the sheet's properties in Visual Basic then you see a (Name) and another Name. I want to rename both in VB code to the same name. How do I do that, because the following code renames only one
sheetExample.Name = "NewName"

Can anyone help?


Renaming A ComboBox

I'm using VB in an excel document..
In this document I create comboBoxes dynamically and give them a name...

sometimes I have to rename the comboBoxes and for some reason they don't get renamed...I'm sure of my code ,I tranced it and verified that the name gets actually changed, but when I open the property window of the comboBox I still get the old name...and the funny thing is that sometimes it gets renamed...

I use an OLEObject to select the comboBox and the name property to change the name...

I'm pretty sure its not a programming issue...
Is there some kind of bug in the microsoft Office?
did something similar ever happened with any of you?


Renaming Files

I am using the Name command in VB (Excel) to change names of files in a directory such as:

Name "oldname.csv" as "newname.csv"

I have defined all the new names as each file has to be differently named
I am trying to insert some code which will skip if a particular file is not in the directory - so if file "A" is not present then please skip to file "b" and so forth

I am little unsure how I do this. Can anyone provide some tips?


Renaming Tabs
Is there a way to rename a tab with what you enter in a cell.

For example you have Sheet 1, Sheet 2, Sheet 3

You enter Meter 1 into cell A1. Is there a way that Sheet 1 can now be renamed Meter 1 without selecting anything and typing it yourself?

Renaming Folders
Hi, I know I can rename a folder with:

Name "C:Old Folder" As "C:New Folder"
but I'd like to loop through a folder and rename all the sub-folders that have specific text in their names.

For example, remove "data" from every sub-folder that has "data" in the name. A folder named "veryolddata" would become "veryold".

Can somebody please explain to me how to do that (is it even possible?) ?

Thank you.

Renaming Worksheets

Is there a way of automatically changing the worksheetnames of workbooks (ie when they are opened, I want to set all available sheets to be Sheet1, Sheet2, Sheet3 etc). I need to save each worksheet under a different filename and this would make it much easier.


Renaming Drivemapping
Let's see... I've got a rather strange question which maybe should not even be posted here.
Anyways... Let's give it a try!
I'm working on a loginscript by using a *.vbs file to provide users some important things during startup. I also use this script to map some network drives.

Dim WshNetwork, WshShell, WshSysEnv

Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive "K:", "\server_nameshare_name"
Lately I was asked if I could rename the mapped drives because someone did not like the "Share_name on Server_name ( K: )" notation.
My Question is if I can change the naming (as shown above) to something else using code?? I know you can click right at the network drive and chose "rename" so I suppose I should be able to perform a rename from code...

Renaming Files
hi all,

just wandering how to change the name of a file in a specific loaction


Copyright 2005-08, All rights reserved