简体   繁体   中英

Copy and paste between workbooks

This is a question and may or may not be achievable but any recommendation is much appreciated.

Is it possible to have one workbook (wrkbookA) open that has all the data and vba code in it. Click button to open/navigate to a directory and select another workbook (wrkbookB). wrkbookB is opened, select a column, that column is copied and pasted into wrkbookA in column A and wrkbookB is closed.

I know this can be achieved using a constant column from wrkbookB but the data is in differnet columns in each workbook in wrkbookB.

I have also looked at column headings and doing the copy that way but it is not an option as there are different columns with similar heading/words.

Thanks everyone.

Since you don't have any way of knowing which Column will need to be selected from workbook B, you're going to need user interaction. that being the case, why not write a sub that will do the following:

  1. Have user select workbook B to open
  2. Place a button in Workbook B attached to code in Workbook A

User then, in Workbook B, selects the column they want copied and push the button which copies that column to Workbook A and closes Workbook B without saving changes.

Sample Code Idea:

Workbooks.Open ...
ActiveSheet.Buttons.Add(427.5, 12.75, 104.25, 36).OnAction = "WorkBookA!MoveColumn"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM