Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 代码中的一个小错误:line If CBool(.Show)Then userFileSaveDialog=.SelectedItems(.SelectedItems.Count)Else End如果我将在End之前替换End If,则为userFileS_Vba_Ms Access 2007 - Fatal编程技术网

Vba 代码中的一个小错误:line If CBool(.Show)Then userFileSaveDialog=.SelectedItems(.SelectedItems.Count)Else End如果我将在End之前替换End If,则为userFileS

Vba 代码中的一个小错误:line If CBool(.Show)Then userFileSaveDialog=.SelectedItems(.SelectedItems.Count)Else End如果我将在End之前替换End If,则为userFileS,vba,ms-access-2007,Vba,Ms Access 2007,代码中的一个小错误:line If CBool(.Show)Then userFileSaveDialog=.SelectedItems(.SelectedItems.Count)Else End如果我将在End之前替换End If,则为userFileSaveDialog=vbnullstring仅获取一个筛选器,请参见,但它对PowerPoint无效,仅对Excel无效?这似乎不起作用,如文档中所述,每个新对话框都会重置过滤器。请展开。这对我有效,但奇怪的是,它开始在的行中抛出错误5。Fil


代码中的一个小错误:line If CBool(.Show)Then userFileSaveDialog=.SelectedItems(.SelectedItems.Count)Else End如果我将在End之前替换End If,则为userFileSaveDialog=vbnullstring仅获取一个筛选器,请参见,但它对PowerPoint无效,仅对Excel无效?这似乎不起作用,如文档中所述,每个新对话框都会重置过滤器。请展开。这对我有效,但奇怪的是,它开始在
的行中抛出错误5。FilterIndex=2
,因此我删除了它,似乎没有任何后果。对迟来的回答的迟来评论…这似乎不起作用(用PPT测试)
 With Application.FileDialog(msoFileDialogSaveAs)
        .Title = "xxx"
        .AllowMultiSelect = False
        .InitialFileName = "xxx.csv"
        '.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
        result = .Show
        If (result <> 0) Then
            ' create file
            FileName = Trim(.SelectedItems.Item(1))
            fnum = FreeFile
            Open FileName For Output As fnum


            ' Write the csv data from form record set
            For Each fld In rs.Fields
               str = str & fld.Name & ", "
            Next

           ' Write header line
           str = Left(str, Len(str) - 2)   ' remove last semi colon and space
           Print #fnum, str
           str = ""

          ' Write each row of data
           rs.MoveFirst
          Do While Not rs.EOF             
            For i = 0 To 40
                str = str & rs(i) & ", "    ' write each field seperated by a semi colon
            Next i
            str = Left(str, Len(str) - 2)   ' remove last semi colon and space
            Print #fnum, str
            str = ""
            rs.MoveNext
           Loop

        ' close file
        Close #fnum
        End If
  End With
FileName = getCSVName(FileName)
...
Function getCSVName(fileName As String) As String
   Dim pos As Long
   pos = InStrRev(fileName, ".")
   If (pos > 0) Then
       fileName = Left$(fileName, pos - 1)
   End If
   getCSVName = fileName & ".CSV"
End Function
For i = 0 To 40
   str = str & rs(i) & ", "    ' write each field seperated by a semi colon
Next i
str = Left(str, Len(str) - 2)   ' remove last semi colon and space
dim delimiter as string
...
For i = 0 To 40
   str = str & delimiter & rs(i)  ' write each field seperated by a semi colon
   delimiter = ","
Next 
Sub Main()
    Debug.Print userFileSaveDialog("unicode", "*.txt")
End Sub

Function userFileSaveDialog(iFilter As String, iExtension As String)

    With Application.FileDialog(msoFileDialogSaveAs)
        Dim aFilterIndex As Long: aFilterIndex = 0&

        For aFilterIndex = 1& To .Filters.Count
            If (InStr(LCase(.Filters(aFilterIndex).Description), LCase(iFilter)) > 0) _
                And (LCase(.Filters(aFilterIndex).Extensions) = LCase(iExtension)) Then

                .FilterIndex = aFilterIndex
                Exit For

            End If
        Next aFilterIndex

        If CBool(.Show) Then
            userFileSaveDialog = .SelectedItems(.SelectedItems.Count)
        Else
            End
        End If
    End With

End Function
Public Function GetSaveFilename() As String

    Dim Dialog As FileDialog: Set Dialog = Application.FileDialog(msoFileDialogSaveAs)
    With Dialog
        .InitialFileName = CurrentProject.Path & "\*.ext"
        .FilterIndex = 2
        .Title = "Save As"
        If .Show <> 0 Then
            GetSaveFilename = .SelectedItems(1)
        End If
    End With
End Function
Dim FileDialogObj As FileDialog

'1.0 Open File Dialog
Set FileDialogObj = Application.FileDialog(msoFileDialogSaveAs)
With FileDialogObj
   .InitialFileName = "C:\"
   .Filters.Item 3  '****This is to set File Dialog Save As to CSV ******
   .Title = "Save As"
   .AllowMultiSelect = False
End With