English 中文(简体)
将Excel电子表格数据输入另一个含有VBA的Excel电子表格
原标题:Importing Excel spreadsheet data into another Excel spreadsheet containing VBA

我们需要在其中写出一张带有《北美自由贸易协定》编码的Excel电子表格;该代码读写并操作第一份工作表格中的数据。

用户将接收含有数据的电子表格,但并不包含VBA代码。 我们需要能够自动从含有数据的数据的电子表格中进口数据。 包含数据的工作表格与载有数据的数据的电子表格的工作表格相同。

理想的情况是,你将打开载有《北美自由贸易协定》编码的电子表格,向用户提供一台自动识别器,使用户能够浏览含有数据的电子表格,点击科索沃,数据将输入。

你们怎样做呢? 必须在Excel电子表格中使用VBA。

许多感谢。

最佳回答

This should get you started: Using VBA in your own Excel workbook, have it prompt the user for the filename of their data file, then just copy that fixed range into your target workbook (that could be either the same workbook as your macro enabled one, or a third workbook). Here s a quick vba example of how that works:

  Get customer workbook...
Dim customerBook As Workbook
Dim filter As String
Dim caption As String
Dim customerFilename As String
Dim customerWorkbook As Workbook
Dim targetWorkbook As Workbook

  make weak assumption that active workbook is the target
Set targetWorkbook = Application.ActiveWorkbook

  get the customer workbook
filter = "Text files (*.xlsx),*.xlsx"
caption = "Please Select an input file "
customerFilename = Application.GetOpenFilename(filter, , caption)

Set customerWorkbook = Application.Workbooks.Open(customerFilename)

  assume range is A1 - C10 in sheet1
  copy data from customer to target workbook
Dim targetSheet As Worksheet
Set targetSheet = targetWorkbook.Worksheets(1)
Dim sourceSheet As Worksheet
Set sourceSheet = customerWorkbook.Worksheets(1)

targetSheet.Range("A1", "C10").Value = sourceSheet.Range("A1", "C10").Value

  Close customer workbook
customerWorkbook.Close
问题回答

数据可以通过工作手册方法或外部参考资料或通过数据输入设施从另一个外壳中提取。

如果你读一读,或者即使你想更新另一本书,这些方法也可以使用。 为此,我们可能不只依靠传统做法。

如欲了解这些技术,请点击,请参见条。





相关问题
import of excel in SQL imports NULL lines

I have a stored procedure that imports differently formatted workbooks into a database table, does work on them then drops the table. Here is the populating query. SELECT IDENTITY(INT,1,1) AS ID ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

Excel date to Unix timestamp

Does anyone know how to convert an Excel date to a correct Unix timestamp?

C# GemBox Excel Import Error

I am trying to import an excel file into a data table using GemBox and I keep getting this error: Invalid data value when extracting to DataTable at SourceRowIndex: 1, and SourceColumnIndex: 1. As ...

Importing from excel "applications" using SSIS

I am looking for any tips or resources on importing from excel into a SQL database, but specifically when the information is NOT in column and row format. I am currently doing some pre-development ...

热门标签