[[20050803123003]] 『CSV形式での自動保存』(けろ) ページの最後に飛ぶ

[ 初めての方へ | 一覧(最新更新順) | 全文検索 | 過去ログ ]

 

『CSV形式での自動保存』(けろ)

あるエクセルファイルをCSV形式で別ファイルに5秒ごとに自動保存したいのですが、うまくできません。

エクセルを開いたままの状態でも他のパソコンからCSVファイルを読めるようにしたいのですが
どうしたらいいでしょうか?

わかる方いらっしゃいましたらよろしくお願いします


 >うまくできません。
 どのように試して、どのように上手く行かないのか説明をお願い致します。

 >エクセルを開いたままの状態でも他のパソコンから
 >CSVファイルを読めるようにしたいのですがどうしたらいいでしょうか
 これは意味が分からないです。
 もっと詳しく具体的に説明をお願い致します。

  (INA)

抽象的な書き方ですみませんでした。過去ログをみながら

Sub auto_open()

myTime = Now + TimeValue("00:00:05")

Application.OnTime myTime, "test"

End Sub

Sub auto_close()

Application.OnTime myTime, "test", , False

End Sub

Sub test()

ThisWorkbook.SaveAs Filename:= _

〜〜 .csv", FileFormat:=xlCSV _, CreateBackup:=False

myTime = Now + TimeValue("00:00:05")

Application.OnTime myTime, "test"

End Sub

のようにマクロに入力しました。最初は入力ミスがあったようで、
やり直しましたら5秒置きにファイルを置き換えますかと聞かれるようになりました。
とりあえず疑問は解決しました。ご迷惑をおかけしました。
あと、置き換えますかと聞かずに勝手に置き換えていってくれる方法がもしあれば
ご教授くださいませ   (けろ)


 ThisWorkbook.saved = true
 を追加してみてください。

 savedプロパティの意味はヘルプを読んでください。
  (INA)

早速のご解答ありがとうございます。

ThisWorkbook.SaveAs Filenameの上の行に
ThisWorkbook.Saved = true

を入れてやってみたのですが、やはり置き換えますか?という
ダイアログが出てきます。もう少しやってみます。


 saveasメソッドを使わないで直接、テキスト出力した方が良いかもしれません。
[[20040909150950]]
  (INA)

いろいろありがとうございます。

SaveAsの代わりに以下のテキスト出力マクロを入れてみました。

これは5秒ごとにファイル名パス名を入力、保存する方式になっています。

たびたびですみませんが、保存するたびにファイル名を

指定しなくてもよくするにはどうすればよろしいでしょうか。

Sub auto_open()

myTime = Now + TimeValue("00:00:05")

Application.OnTime myTime, "test"

End Sub

Sub auto_close()

Application.OnTime myTime, "test", , False

End Sub

Sub test()
' Dimension all variables.

 Dim DestFile As String
         Dim FileNum As Integer
         Dim ColumnCount As Integer
         Dim RowCount As Integer

         ' Prompt user for destination file name.
         DestFile = InputBox("Enter the destination filename" _
            & Chr(10) & "(with complete path):", "Quote-Comma Exporter")
         FileNum = FreeFile()

         ' Turn error checking off.
         On Error Resume Next

         ' Attempt to open destination file for output.
         Open DestFile For Output As #FileNum

         ' If an error occurs report it and end.
         If Err <> 0 Then
            MsgBox "Cannot open filename " & DestFile
            End
         End If

         ' Turn error checking on.
         On Error GoTo 0

         ' Loop for each row in selection.
         For RowCount = 1 To Selection.Rows.Count

            ' Loop for each column in selection.
            For ColumnCount = 1 To Selection.Columns.Count

               ' Write current cell's text to file with quotation marks.
               Print #FileNum, """" & Selection.Cells(RowCount, _
                  ColumnCount).Text & """";

               ' Check if cell is in last column.
               If ColumnCount = Selection.Columns.Count Then
                  ' If so, then write a blank line.
                  Print #FileNum,
               Else
                  ' Otherwise, write a comma.
                  Print #FileNum, ",";
               End If
            ' Start next iteration of ColumnCount loop.
            Next ColumnCount
         ' Start next iteration of RowCount loop.
         Next RowCount

         ' Close destination file.
         Close #FileNum
ThisWorkbook.Saved = True
myTime = Now + TimeValue("00:00:05")
Application.OnTime myTime, "test"
End Sub

Sub kosin()
If ThisWorkbook.Path <> "" Then
Range("B2:G9").Select

    Selection.Copy
    Windows("hozon.csv").Activate
    Range("B2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Windows("test.xls").Activate
ThisWorkbook.Saved = True
End If
Application.OnTime Time() + TimeValue("00:00:05"), "kosin"
End Sub
CSV形式で保存するところは、形式を選択して値の貼付けを使いマクロに保存しました。
hozon.csvファイルをたちあげていないといけませんがとりあえず解決しました。
INAさんありがとうございました。


コメント返信:

[ 一覧(最新更新順) ]


YukiWiki 1.6.7 Copyright (C) 2000,2001 by Hiroshi Yuki. Modified by kazu.