1
4

More than 3 years have passed since last update.

ファイル名作成のための日付文字列を作成する Python vba

Posted at

スクレイピングで必須なのがファイル名の作成。
ファィル名は日付+連番のケースが一番おおいでしょうか
多数の場合は日付+時刻でよいのですが、
数が少ない場合は日付+連番が一番人気なので、
ファイル名作成の方法をメモしました。

Pythonの場合

前提
Windows
Python3.7
以下は 日付+連番のCSVファイル名を作成する場合
datetime.date.today() をstrftimeでフォーマットすると文字列として扱えるので
希望の文字列を末尾に追加することができます。

python
import datetime
hizuke = datetime.date.today()
hizuke = hizuke.strftime('%Y-%m-%d')
file1 = hizuke+"-1.csv"  #2020-08-11-1.csv ※今日の日付
file2 = hizuke+"-2.csv"    #2020-08-11-2.csv

詳しい日付の書式はこちら
https://docs.python.org/ja/3.6/library/datetime.html#strftime-strptime-behavior

vbaの場合

vba
 Dim strFileNm As String
 strFileNm = Format(Now(), "yyyy-mm-dd") & "-1.csv" '2020-08-11-1.csv ※今日の日付

詳しい日付の書式はこちら
https://docs.microsoft.com/ja-jp/dotnet/api/microsoft.visualbasic.strings.format?view=netcore-3.1

vbaの場合日付の書式設定がエクセルで使っているものと同じなのでなじみ深いです。

1
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
4