VBA - Get Cell Values from other workbook without opening

时光毁灭记忆、已成空白 提交于 2019-12-11 02:32:35

问题


I'm working to get the cell value of other workbook without opening it.

And here's some of my codes:

Range("F3")= "='C:\inetpub\vhosts\hotdogko.com\httpdocs\private\excel\[Launch Pad.xls]Sheet1'!$B$12 "

This code is working well when data type of the cell value to pull is Date, Integer or Any not String data type. But it wont work correctly to string data type, it just returning #N/A.

Thanks for someone who can give me an answer for this problem.


回答1:


You can try with following answer

Sub ReadDataFromAnotherWorkBook()

    ' Open Workbook A with specific location
    Dim src As Workbook
    Set src = Workbooks.Open("C:\Users\chan.yoonghon\Desktop\Excel\BookA.xlsx", True, True)

    Dim valueBookA As Integer
    Dim valueBookB As Integer

    valueBookA = src.Worksheets("sheet1").Cells(1, 1)
    Cells(1, 1).Value = valueBookA

    ' Close Workbooks A
    src.Close False
    Set src = Nothing

     ' Dialog Answer
    MsgBox valueBookA
End Sub



回答2:


If you add the text function after the equal It should work something like:

Range("F3")= "=text("'C:\inetpub\vhosts\hotdogko.com\httpdocs\private\excel\[Launch Pad.xls]Sheet1'!$B$12 " ;"") "

Perhaps you should check if the " are correct because sometimes you have to add double "".




回答3:


Try it without using quotation marks (" "). It should help.



来源:https://stackoverflow.com/questions/14192610/vba-get-cell-values-from-other-workbook-without-opening

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!