文字墙传入,要小心。
我有一个电子表格,对这些功能特别重要,有许多指向网络文档的链接。这些链接有一个地址(基本URL),一个子地址(#page =,需要在子地址中,因此Excel不会被#搞糊涂),以及一个显示文本,即页码。此电子表格包含其他人制作的XML地图。
如果我将电子表格正常导出到XML,它只导出 链接的显示文本(因此,页码,但不是实际的URL)。我希望XML数据保存链接而不是显示文本。
我选择的方法是使用BeforeXMLExport和AfterXMLExport
这个问题的主要问题是,由于实际导入时有两个电子表格,我的XML文件有一堆无用的数据 - 它还导出包含显示文本而不是URL的电子表格。复制到不同的工作簿,然后将该工作表移动到原始书籍避免这个问题?如果是这样,我该怎么做呢?
从不太重要的角度来看,我认为这不是最有效的方法。我特别关注的是
1)删除和重命名工作表似乎不必要地复杂,但我无法让Worksheet.Copy和Worksheet.Paste函数相互配合使用
2)最后重新映射更改后的表格似乎是不必要的。有没有办法在保留XML地图的同时复制电子表格?或者,我目前只是使用录制的宏重新映射。这是通过VBA以编程方式实现的吗?
这是我目前的代码
Private Sub Workbook_BeforeXmlExport(ByVal Map As XmlMap, ByVal Url As String, Cancel As Boolean)
Worksheets("Input Form").Copy After:=Worksheets("Input Form") 'Copies worksheet as it is prior to exporting
Sheets("Input Form").Activate
Dim cl As Range
For Each cl In Range("A1:BD4") 'Loops through worksheet. The range would have to be changed later on
If cl.Hyperlinks.Count <> 0 Then 'Checks cells for a link
cl.Value = cl.Hyperlinks(1).Address & cl.Hyperlinks(1).SubAddress 'If the cell has a link, change the value of the cell to its hyperlink
End If
Next cl
End Sub
Private Sub Workbook_AfterXmlExport(ByVal Map As XmlMap, ByVal Url As String, ByVal Result As XlXmlExportResult)
Application.DisplayAlerts = False 'For sheet deletion
Application.ScreenUpdating = False 'Efficiency, hide ugly workaround
Worksheets("Input Form").Delete 'Deletes changed worksheet
Worksheets("Input Form (2)").Name = "Input Form" 'Changes the name of the copy into that of the original
Application.Run "MapXML" 'Copying seems to lose the XML map. This macro, which I recorded manually, exists to remap. There is probably a way to do this through VBA, although I have yet to find it.
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub