Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA (excel) - How to set the source file

Status
Not open for further replies.

baltog

Programmer
Dec 19, 2002
22
0
0
US
Hi,

I'm working with VBA Excel. Here's the situation.
I want to transfer the data from 1 excel file to
another file. How do i set the source file.

Here's what i started:

Private xlOutApp As Excel.Application
Private xlOutBook As Excel.Workbook
Private xlOutSheet As Excel.Worksheet

'initialize excel components
Set xlOutApp = CreateObject("Excel.Application")
xlOutApp.SheetsInNewWorkbook = 1
Set xlOutBook = xlOutApp.Workbooks.Add
Set xlOutSheet = xlOutBook.Worksheets(1)

These variables for the source file.
Please help. tnx in advance!
 
Do you have an active document and want to create another to copy data to? Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
take a look at this...

Workbooks.Add
Windows("Book1").Activate
Range("A1").Select
Selection.Copy
Windows("Book2").Activate
ActiveSheet.Paste
Range("C5").Select

you will need to replace the items in "" as nessisary Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
Hi Cube,

Yup i have active document which happens to be the Destination file. My app is running prog but just want to modify some functionality. Before i am getting data using recordset: Something like this

continuation of the code.

xlOutSheet.Cells(Inc1(nRow), 2) = CStr(ChkStrNull(rsSource("Job Type")))

now i want it to be like this:

xlOutSheet.Cells(Inc1(nRow), 2) = newExcelSheet.Cells(1,6)

now my problem is how to set up the source of newExcelSheet. It should get data from existing file.
The problem with the recordset is that it can handle only 255 characters which is not applicable to my app. Now i want to copy cell to cell.

Thanks in advance!
 
ok...

you have an active document.... ("Book1")

Workbooks.Add 'Create a new Doc "Book2"
Windows("Book1").Activate 'Reactivate Book1
Range("A1").Select 'Select Cell "A1"
Selection.Copy 'Copy it
Windows("Book2").Activate 'Activate the new doc Book2
Range("A1").Select 'Select Cell "A1"
Selection.Paste 'Paste it
Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
forget what I said above...

I answered your other thread... thread707-443420 Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
CubE101,
It's very good of you to attempt to follow this question across multiple threads but.....

Baltog,

To avoid the confusion that we all feel trying to follow several different threads on the same subject, you may find that reading faq222-2244 will get you tidier answers, and make it easier for contributors to help
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top