Copy an Excel File and Update some of it's cells
I am adding this to my app that I made yesterday that creates new project folders and copies files over.
Now I would like to beable to edit the excel files as I copy them over. I have started to play around with the excel stuff for VB and I got it to create a new file, but I need help on editing it as I copy it. Ideally I would like to be able to only change some cells. Like tell it to delete everything in one cell and replace it with something.
Thanks
[475 byte] By [
dustinto] at [2007-12-23]
If I had to use those functions...
Im thinking more like...
Copy File (Already doing that)
Open Excel File - At new location
Make Changes
Save File
Would that work?
'OPEN THE EXCEL FILE
Dim wb As Excel.Workbook = _
ThisApplication.Workbooks.Open("C:\YourPath\YourWorkbook.xls")
'SELECT MY WORKSHEET
'ThisApplication.ActiveWorkbook.Sheets(1).Select()
Dim xlws As Excel.Worksheet = ThisApplication.ActiveWorkbook.Sheets(1).Select()
'Edit WORKSHEET
xlws.Cells(A, 1) = "TEXT HERE"
'SAVE THE EXCEL FILES (ALL OPEN WORKBOOKS)
Dim wb As Excel.Workbook
For Each wb in ThisApplication.Workbooks
wb.Save
Next wb
dustinto wrote: |
| If I had to use those functions... Im thinking more like... Copy File (Already doing that) Open Excel File - At new location Make Changes Save File Would that work? |
|
Yes...that will work....
Just as a note...You are using Visual Basic for Applications which is not the same as Visual Basic .NET, for futher help regarding VBA please see the following forum:
http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=74&SiteID=1
Moving this thread to the VBA forum