0

既存のtxtファイル(file1)のOpenFileボックスを表示し、新しいファイルを作成して新しいtxtファイル(file2)のSaveAsボックスを表示するコードを探しています。後で file2 に保存される file1 の内容。

これまでのところ、最初の部分は問題なく動作するようになりました。2番目の部分が間違っていることは知っていますが、どうすればよいかわかりません。

これまでの私のコード;

infilename$ = Application.GetOpenFilename("Neutral Files (*.txt),*.txt", , "Open
Neutral File", "OPEN", False)
If infilename$ = "False" Then
    msg = MsgBox("No input file selected. Press OK to retry or cancel to quit",vbOKCancel)
    If msg = vbOK Then
        Do While msg <> vbCancel  'loop until user presses cancel
            infilename$ = Application.GetOpenFilename("Neutral Files (*.r01),*.r01", , "Open Neutral File", "OPEN", False)
            If infilename$ = "False" Then
                msg = MsgBox("No input file selected. Press OK to retry or cancel to quit", vbOKCancel)
            End If
        Loop
    ElseIf msg = vbCancel Then Exit Sub
    End If
End If

outfilename$.SaveAs =:"FileName"infilename.txt",False"

If outfilename$ = "False" Then
    msg = MsgBox("No output file selected. Press OK to retry or cancel to quit", vbOKCancel)

    If msg = vbOK Then
        Do While msg <> vbCancel  'loop until user presses cancel
            outfilename$ = Application.SaveAsFilename("Neutral Files (*.r01),*.r01", , "Save As Output", "SAVE", False)

            If outfilename$ = "False" Then
                msg = MsgBox("No output file selected. Press OK to retry or cancel to quit", vbOKCancel)
            End If
        Loop
    ElseIf msg = vbCancel Then Exit Sub
    End If
End If
4

1 に答える 1

2

この線

outfilename$.SaveAs =:"FileName"infilename.txt",False"

確かにかなり間違っているように見えます。

代わりにこれを試して、ファイルを保存するためのダイアログをポップアップすることができます

outfilename$ = Application.GetSaveAsFilename(infilename$, "Neutral Files (*.txt),*.txt", , "Save file", "SAVE")

更新:完全なコードは

Sub test()
Dim outfilename as Variant
Dim infilename as Variant
Dim msg As Variant
infilename = Application.GetOpenFilename("Neutral Files (*.txt),*.txt", , "Open Neutral File", "OPEN", False)
If infilename = "False" Then
    msg = MsgBox("No input file selected. Press OK to retry or cancel to quit", vbOKCancel)
    If msg = vbOK Then
        Do While msg <> vbCancel  'loop until user presses cancel
            infilename = Application.GetOpenFilename("Neutral Files (*.r01),*.r01", , "Open Neutral File", "OPEN", False)
            If infilename = "False" Then
                msg = MsgBox("No input file selected. Press OK to retry or cancel to quit", vbOKCancel)
            End If
        Loop
    ElseIf msg = vbCancel Then Exit Sub
    End If
End If

 outfilename = Application.GetSaveAsFilename(infilename, "Neutral Files (*.txt),*.txt", , "Save file", "SAVE")

If outfilename = "False" Then
    msg = MsgBox("No output file selected. Press OK to retry or cancel to quit", vbOKCancel)

    If msg = vbOK Then
        Do While msg <> vbCancel  'loop until user presses cancel
            outfilename = Application.SaveAsFilename(infilename, "Neutral Files (*.r01),*.r01", , "Save As Output", "SAVE")

            If outfilename = "False" Then
                msg = MsgBox("No output file selected. Press OK to retry or cancel to quit", vbOKCancel)
            End If
        Loop
    ElseIf msg = vbCancel Then Exit Sub
    End If
End If

End Sub
于 2013-07-12T11:37:22.273 に答える