|
-
Apr 17th, 2007, 01:15 AM
#1
Thread Starter
Member
[RESOLVED] How to add data to an existing Excel & save wid same name??
hey guys!
I have been working on a code to add certain data to a template excel file. The problem i have now is that i am not able to save the appended excel file with the same name as the original template file. When I try to do dat, the code overwrites the template file.
Is there any way to save a template excel file after adding some data with its original name without overwriting the original data in it.
I am currently using obook.SaveAs command. (where obook is the workbook object)
please advise
cheers
Abhilash
Last edited by Abhilash007; Apr 17th, 2007 at 10:19 PM.
-
Apr 18th, 2007, 12:42 PM
#2
Re: How to add data to an existing Excel & save wid same name??
Thats because it soundds like you are opening the template and not creating a new document based upon the template.
Something like this will do it.
oApp.Documents.Add "C:\MyTemp.dot", False, wdNewBlankDocument, True
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 18th, 2007, 05:30 PM
#3
Re: How to add data to an existing Excel & save wid same name??
You can't have 2 files of the same name and type in the same folder. It's something like having 2 documents written on the same side of the same piece of paper - the concept is wrong.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Apr 18th, 2007, 07:16 PM
#4
Re: How to add data to an existing Excel & save wid same name??
That will be prevented as when you create a new document based upon a template it will name it - "MyCustomTempate1.doc", "MyCustomTemplate2.doc", etc. never overwritting the dot file since that is the way templates work when documents are created based upon one.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 19th, 2007, 01:38 AM
#5
Thread Starter
Member
Re: How to add data to an existing Excel & save wid same name??
Hey!
I can understand wad you say but the thing is i just want to add data to a present excel file and save it with the same name. I do not require the original template file, i only need the final appended file..
At the moment when i try to save the final with the same name as its original name, then i get a message asking me to replace original file.
If i replce original, all the data in the original template will be erased and only the newly added data is shown.
I hope you can understand my problem
PLease advise
cheers
Abhilash
-
Apr 19th, 2007, 02:01 AM
#6
Re: How to add data to an existing Excel & save wid same name??
So then your not adding data to a workbook generated from a custom template?
" to add certain data to a template excel file."
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 19th, 2007, 03:21 AM
#7
Thread Starter
Member
Re: How to add data to an existing Excel & save wid same name??
It is a Custom template in the sense that i have created it. When i created it, i did input some data which are constant. on top that constant data i have to write a code which calculates certain data and adds onto the excel file. now after the code adds the data, i want to save the excel file with the same filename. that is i just want to add data to a file and not make any copy.
cheers
Abhilash
-
Apr 19th, 2007, 03:53 AM
#8
Re: How to add data to an existing Excel & save wid same name??
Ok, but is this an actual template file with an extension of xlt? or a standard workbook with an extension of xls?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 19th, 2007, 04:07 AM
#9
Thread Starter
Member
Re: How to add data to an existing Excel & save wid same name??
It is a standard workbook with ext .xls
-
Apr 19th, 2007, 04:09 AM
#10
Re: How to add data to an existing Excel & save wid same name??
Ah, ok then we are now talking about the same thing lol.
Does the .Save work better for you then?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 19th, 2007, 04:31 AM
#11
Thread Starter
Member
Re: How to add data to an existing Excel & save wid same name??
Hey Rob!
i tried .Save also... this is my test code..
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oExcel As New Object
Dim oBook As Object
Dim oSheet As Object
oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.Open("C:\Unicode.xls")
oSheet = oBook.ActiveSheet
oSheet.Range("C4").Value = "Order ID"
oSheet.Range("C5").Value = "Amount"
oSheet.Range("C6").Value = "Tax"
oBook.Save("C:\Unicode.xls") 'The Error occurs here
oSheet = Nothing
oBook = Nothing
oExcel.Quit()
oExcel = Nothing
GC.Collect()
MessageBox.Show("xls saved")
End Sub
End Class
It now shows a new error at the line ' oBook.Save("C:\Unicode.xls") '
Code:
Number of parameters specified does not match the expected number.
-
Apr 19th, 2007, 09:03 AM
#12
Re: How to add data to an existing Excel & save wid same name??
Try oBook.Save
oBook.Save("C:\Unicode.xls") is Save As, not Save.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Apr 19th, 2007, 12:32 PM
#13
Re: How to add data to an existing Excel & save wid same name??
As per my suggestion, yes .Save is the way to do it and since its .Save you dont need to specify any args as there are none.
oBook.Save()
Now you are switchng back as you said you just needed to save it as the file is open so .Save is what you want. Now if you are requesting it to be renamed again as well then you have to go back and use .SaveAs which will give you the overwrite prompt.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 23rd, 2007, 01:49 AM
#14
Thread Starter
Member
Re: How to add data to an existing Excel & save wid same name??
hey..
yep.. dat has solved my prob... thx a lot
cheers
Abhilash
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|