excel - Open XML File in same workbook as Macro -
i writing macro import xml info , clever things it. next code opens xml new workbook - can advise how open current workbook?
dim fnameandpath variant fnameandpath = application.getopenfilename(filefilter:="xml files (*.xml), *.xml", title:="select file opened") if fnameandpath = false exit sub workbooks.open filename:=fnameandpath
cheers
edit - here code job
sub openxml() dim filestoopen dim x integer dim wkball workbook dim wkbtemp workbook dim sdelimiter string dim newsheet worksheet on error goto errhandler application.screenupdating = false sdelimiter = "," filestoopen = application.getopenfilename _ (filefilter:="xml files (*.xml), *.xml", _ multiselect:=true, title:="xml file open") if typename(filestoopen) = "boolean" msgbox "no files selected" goto exithandler end if x = 1 ubound(filestoopen) set wkbtemp = workbooks.open(filename:=filestoopen(x)) 'wkbtemp.sheets(1).copy wkbtemp.sheets(1).cells.copy ' here want create new sheet , paste sheet set newsheet = thisworkbook.sheets.add newsheet .name = "original_xml" .pastespecial end application.cutcopymode = false wkbtemp.close next x end sub()
you can import xml workbook way without opening it:
thisworkbook.xmlimport url:= _ s_filepath, importmap:=nothing, _ overwrite:=true, destination:=sheets("sheet1").range("a1")
in code this:
sub openxml() dim filestoopen dim x integer dim sdelimiter string dim newsheet worksheet on error goto errhandler application.screenupdating = false sdelimiter = "," filestoopen = application.getopenfilename _ (filefilter:="xml files (*.xml), *.xml", _ multiselect:=true, title:="xml file open") if typename(filestoopen) = "boolean" msgbox "no files selected" goto exithandler end if activeworkbook x = 1 ubound(filestoopen) set newsheet = .sheets.add newsheet.name = "original_xml_" & x application.displayalerts = false .xmlimport url:= _ filestoopen(x), importmap:=nothing, _ overwrite:=true, destination:=newsheet.range("a1") application.displayalerts = true next x end exithandler: errhandler: end sub
xml excel vba
No comments:
Post a Comment