测试文件版本Excel 2007
测试数据文件
添加开发工具菜单
创建一个宏
编写模块代码
创建向导窗口
为窗口编写功能代码
以下为运行效果
下面贴出代码
模块代码
Public lastListIndex As Integer
Sub ExportLanguage()
UserForm1.ComboBox1.Clear
For i = 2 To 10 Step 1
If Cells(1, i).value <> "" Then
UserForm1.ComboBox1.AddItem (Cells(1, i))
Else
Exit For
End If
Next i
UserForm1.ComboBox1.listIndex = lastListIndex
UserForm1.Show
End Sub
窗口功能代码
Private Sub UserForm_Initialize()
lastListIndex = 0
End Sub
Private Sub CommandButton1_Click()
Dim listIndex As Integer
listIndex = UserForm1.ComboBox1.listIndex
lastListIndex = listIndex
Dim path As String
path = ThisWorkbook.path & "\" & ActiveSheet.Name & ".txt"
Dim key As String
Dim value As String
Dim colIndex As Integer
Dim empyCount As Integer
Dim i As Integer
colIndex = listIndex + 2
empyCount = 0
i = 0
Open path For Output As #1
Do While empyCount < 2
i = i + 1
key = Cells(i, 1).value
If key <> "" Then
value = Cells(i, colIndex)
Print #1, key & Chr(9) & value
empyCount = 0
Else
empyCount = empyCount + 1
End If
Loop
Close #1
MsgBox ("导出成功" & Chr(10) & path)
UserForm1.Hide
End Sub