hallo alle zusammen,
habe ein excel makro vorliegen,das mir ein vorliegende excel tabelle in eine xml datei exportiert und auf einem definierten share platziert (im Beispiel C:\lokal\) ... ich würd nun gerne die entstehende xml datei auf einem https webdav verzeichnis ablegen. pfad, user, pw sind bekannt ... wie kann ich dies am besten realisieren? bin scho leider seit langem raus aus der vb scene und würde mich über unterstützung freuen! vielen dank im voraus
VB XML Makro
dies habe ich gefunden, wie binde ich es am besten ein (soll denn upload einer lokalen datei auf ein webdav verzeichnis realisieren):
habe ein excel makro vorliegen,das mir ein vorliegende excel tabelle in eine xml datei exportiert und auf einem definierten share platziert (im Beispiel C:\lokal\) ... ich würd nun gerne die entstehende xml datei auf einem https webdav verzeichnis ablegen. pfad, user, pw sind bekannt ... wie kann ich dies am besten realisieren? bin scho leider seit langem raus aus der vb scene und würde mich über unterstützung freuen! vielen dank im voraus
VB XML Makro
VB.NET-Quellcode
- Option Explicit
- Sub XML_Export()
- Dim strSpaltenName
- strSpaltenName = ""
- Dim oSheet As Worksheet
- Set oSheet = Application.ActiveSheet
- ' Spaltenanzahl ermitteln
- Dim intCol
- intCol = 1
- Do Until Cells(1, intCol) = ""
- intCol = intCol + 1
- Loop
- intCol = intCol - 1
- 'MsgBox "Habe " & intCol & " Spalten gefunden...."
- ' Neue Datei schreiben, wenn Spaltenanzahl > 0
- If intCol > 0 Then
- Dim strFileName As String
- strFileName = "C:\Lokal\"
- strFileName = strFileName + oSheet.Name + "_" + CStr(Date)
- strFileName = strFileName + ".xml"
- ' Alte Datei löschen
- If Dir(strFileName) > "" Then Kill strFileName
- Open strFileName For Output As #1
- Dim intRow As Integer
- intRow = 2
- Dim x
- Print #1, "<?xml version=""1.0"" encoding=""iso-8859-1""?>"
- Print #1, MakeStartTag("Ergebnismenge")
- Do Until Cells(intRow, 1) = ""
- Print #1, vbTab & MakeStartTag(oSheet.Name)
- For x = 2 To intCol '2, weil Index in Spalte 1 ausgeblendet werden soll
- strSpaltenName = ReplaceSpecialChar(CStr(Cells(1, x).Value))
- Print #1, vbTab & vbTab & MakeStartTag(strSpaltenName) & FormatCell(Cells(intRow, x)) & MakeEndTag(strSpaltenName)
- Next
- intRow = intRow + 1
- Print #1, vbTab & MakeEndTag(oSheet.Name)
- Loop
- Print #1, MakeEndTag("Ergebnismenge")
- Close #1
- If intRow - 2 = 1 Then
- MsgBox "In die Datei '" & strFileName & "' wurde " & intRow - 2 & " Datensatz geschrieben!"
- Else
- MsgBox "In die Datei '" & strFileName & "' wurden " & intRow - 2 & " Datensätze geschrieben!"
- End If
- End If
- End Sub
- Function MakeStartTag(ByVal Text As String) As String
- MakeStartTag = "<" & Text & ">"
- End Function
- Function MakeEndTag(ByVal Text As String) As String
- MakeEndTag = "</" & Text & ">"
- End Function
- Function FormatCell(oCell As Range)
- If IsDate(oCell.Value) Then
- FormatCell = Format(oCell.Value, "yyyy-mm-dd\Thh:mm:ss")
- Exit Function
- End If
- 'If IsNumeric(oCell.Value) Then
- ' FormatCell = Replace(CStr(oCell.Value), ",", ".")
- ' Exit Function
- ' End If
- If InStr(1, oCell.Value, "&") Then
- FormatCell = Replace(CStr(oCell.Value), "&", "_x0026_")
- Exit Function
- End If
- FormatCell = oCell.Value
- End Function
- Function ReplaceSpecialChar(ByVal strText As String) As String
- If InStr(1, strText, " ") Then
- strText = Replace(strText, " ", "_x0020_")
- End If
- If InStr(1, strText, "&") Then
- strText = Replace(strText, "&", "_x0026_")
- End If
- ReplaceSpecialChar = strText
- End Function
dies habe ich gefunden, wie binde ich es am besten ein (soll denn upload einer lokalen datei auf ein webdav verzeichnis realisieren):
VB.NET-Quellcode
- Dim objRecord As New adodb.Record
- Dim objStream As New adodb.Stream
- sFilename = sFileToUpload
- objRecord.Open sFilename, "URL=" & sDAVFolder, adModeReadWrite, adCreateOverwrite, , sUserName, sPassword
- objStream.Open objRecord, adModeReadWrite, adOpenStreamFromRecord
- objStream.Type = adTypeBinary
- objStream.LoadFromFile sFileToUpload
- objStream.Flush