如何在VBA中添加没有额外工作簿的XML文件? [英] How can I add an XML-file without an extra workbook in VBA?

查看:99
本文介绍了如何在VBA中添加没有额外工作簿的XML文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用VBA在excel的工作簿的表2中添加了一个xml文件。虽然每次单击按钮,excel仍然在我的原始工作簿中添加工作簿。我怎么能对它进行编码才能不再发生?



我尝试过的事情:

< br $>

I've made it to add an xml file in sheet 2 of the present workbook in excel using VBA. Though every time I click the button, excel is nevertheless adding a workbook in my Original workbook. How can I code this for it not to happen anymore please?

What I have tried:

Private Sub CommandButton1_Click()
' AddXml
'
Dim fldg As FileDialog
Dim foldername As String
Dim strTargetFile As String
Dim wb As Workbook
 

Set fldg = Application.FileDialog(msoFileDialogFilePicker)
With fldg
.Title = "Select an XML to import"
.AllowMultiSelect = False
If .Show <> -1 Then GoTo NextCode
foldername = .SelectedItems(1)
End With
NextCode:
GetFolder = foldername
Set fldg = Nothing
 
strTargetFile = foldername
Set wb = Workbooks.OpenXML(Filename:=strTargetFile, LoadOption:=xlXmlLoadImportToList)
Application.DisplayAlerts = True
 
wb.Sheets(1).UsedRange.Copy ThisWorkbook.Sheets("Sheet2").Range("A1")
wb.Close False
Application.ScreenUpdating = True
 
End Sub

推荐答案

好像,你已经回答了你的问题:如何在excel的表2中显示所选的XML文件 [ ^ ] 。



如果没有,你必须删除这个问题并回答你之前的问题,然后你必须通过添加necesarry详细信息来更新问题。
Seems, you already answered to your question: How do I show the selected XML file in sheet 2 of excel[^].

If not, you have to remove this question and answer to your previous question, then you have to update a question by adding necesarry details.


这篇关于如何在VBA中添加没有额外工作簿的XML文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆