首页 > 解决方案 > 从 Excel 电子表格中提取信息

问题描述

我目前正在尝试创建一个程序来从 Excel 电子表格中提取信息,不幸的是我在这场战斗中没有一只狗,哈哈。所以无论如何,我基本上都会做报价和估计,并且我已经设置了 Excel,我只需要将特定信息从单个单元格中提取为“100 美元/英尺”格式。相反,我得到 100.3216 ....... 另外,我正在寻找一种方法来仅使用短键来生成和重置标签框值而不是多个按钮。

这是我到目前为止所拥有的......

Private Sub GetQuote_Click()

Dim objExcel As New Excel.Application

Dim exWb As Excel.Workbook

Set exWb = objExcel.Workbooks.Open("C:\Users\tcreel\Documents\quoteautofill.xlsx")

ThisDocument.Label1.Caption = "Horizontal Straight Housing & Cable                         " & _
     exWb.Sheets("Quote Sheet").Cells(7, "O") 'horizontal footage price'

ThisDocument.Label2.Caption = "Vertical Straight Housing & Cable                               " & _
     exWb.Sheets("Quote Sheet").Cells(8, "O") 'verticle footage price'

ThisDocument.Label3.Caption = "Horizontal 90-degree Elbow & Cable                          " & _
     exWb.Sheets("Quote Sheet").Cells(9, "O") ' hor.90° elbow price'

ThisDocument.Label4.Caption = "Vertical 90-degree Elbow & Cable                                " & _
     exWb.Sheets("Quote Sheet").Cells(10, "O") 'vert. 90° price'

exWb.Close

Set exWb = Nothing

End Sub

标签: excelvbams-word

解决方案


您应该使用如下代码:

exWb.Sheets("Quote Sheet").Cells(7, "O").Text

(如果您的工作簿以所需的输出格式显示内容),或者:

Format(exWb.Sheets("Quote Sheet").Cells(7, "O").Value, "$#,##0.00")

其中 "$#,##0.00" 指定所需的输出格式。


推荐阅读