Excel 将组合框列表保存到.txt文件中

Excel 将组合框列表保存到.txt文件中,excel,vba,Excel,Vba,VBA:有没有办法将组合框列表保存到.txt文件中 我在这里做了一个,把一个txt文件的信息放入一个组合框 Dim InFile As Integer InFile = FreeFile Open "MYFILE.txt" For Input As InFile While Not EOF(InFile) Line Input #InFile, NextTip ComboBox1.AddItem NextTip ComboBox1.ListIndex = 0 Wend Clos

VBA:有没有办法将组合框列表保存到.txt文件中

我在这里做了一个,把一个txt文件的信息放入一个组合框

Dim InFile As Integer
InFile = FreeFile
Open "MYFILE.txt" For Input As InFile
While Not EOF(InFile)
  Line Input #InFile, NextTip
   ComboBox1.AddItem NextTip
   ComboBox1.ListIndex = 0

Wend
Close InFile

下面的宏将把指定组合框中的项目列表打印到指定的文本文件中。相应地更改宏的名称以及目标文件的路径和文件名

    'Force the explict declaration of variables
    Option Explicit

    Private Sub CommandButton1_Click()

        'Declare the variables
        Dim destFile As String
        Dim fileNum As Long
        Dim i As Long

        'Assign the path and file name for the destination file (change accordingly)
        destFile = "C:\Users\Domenic\Desktop\sample.txt"

        'Get the next available file number
        fileNum = FreeFile()

        'Print list items from combobox to destination file
        Open destFile For Output As #fileNum
            With Me.ComboBox1
                For i = 0 To .ListCount - 1
                    Print #fileNum, .List(i)
                Next i
            End With
        Close #fileNum

        MsgBox "Completed!", vbExclamation

    End Sub