ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   insert data from one excel file into another (https://www.excelbanter.com/excel-discussion-misc-queries/1004-insert-data-one-excel-file-into-another.html)

Leonard

insert data from one excel file into another
 
Is there any way to insert data from one excel file into another without
doing copy and pasting? I need to automate the process of inserting data but
I cannot use copy-paste, because it puts data on a clipboard, and my Excel
VBA program runs in a multi-user environment. So if one instance of a program
is copying data into clipboard, and another instance is pasting it at the
same time, it will paste incorrect data.

Thank you

Leonard.


Huw

You'll need both spreadsheets open, but try this;

Option Explicit

Sub MyMacro()
Dim MyVariable As String

Windows("File2.xls").Activate 'Use the window name to select the file
MyVariable = Range("A1") 'Use a variable to store the data from "A1".

Windows("File1.xls").Activate 'Select the second workbook.
Range("A1").Select 'Select cell "A1".
ActiveCell.Text = MyVariable 'Use .Text to copy the data.
End Sub


"Leonard" wrote:

Is there any way to insert data from one excel file into another without
doing copy and pasting? I need to automate the process of inserting data but
I cannot use copy-paste, because it puts data on a clipboard, and my Excel
VBA program runs in a multi-user environment. So if one instance of a program
is copying data into clipboard, and another instance is pasting it at the
same time, it will paste incorrect data.

Thank you

Leonard.



All times are GMT +1. The time now is 09:30 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com