« 2018年7月 | トップページ | 2018年12月 »

2018年11月

2018年11月25日 (日)

iCalendar形式のファイルをExcelで生成する1

iCalendar形式(以下iCal形式とする)のファイルには、
Googleカレンダーなどスケジュールアプリで出力できる
スケジュールのデータが含まれます。

この形式のファイルで
スケジュールアプリ間でスケジュールのやり取りが出来ます。

iCal形式のファイルをExcelで生成したいのですが、
iCal形式って何?
という所から始めていきます。

今回はiCal形式のデータ内容について調べます。

方法としてGoogleカレンダーで予定を入力して
そのスケジュールをiCal形式でエクスポートします。
エクスポートしたファイルの内容を調べていきます。

Googleカレンダーで
全てのスケジュールをエクスポートするには
「設定」-「インポート/エクスポート」-「エクスポート」
の順に選択してください。
特定のカレンダーのみエクスポートする場合は
「設定」をクリックしたあと
マイカレンダーの出力したい項目を選択して
「カレンダーをエクスポート」をクリックしてください。
詳しくは下記参照
Googleサイト内「Google カレンダーを書き出す

出力されたファイルはiCal形式で
拡張子は「.ics」になります。
この拡張子を「.txt」に修正すると
Windowsのメモ帳で内容を見たり、編集できるようになります。

Googleカレンダーの入力画面と出力されたファイルを
下の画像で比較していきます。
よく使う部分のみデータを残し、他は削除してあります。
Vba20181125a

BEGIN:VCALENDAR

END:VCALENDAR

の部分はiCal形式の必須部分です。

BEGIN:VEVENT

END:VEVENT

の部分はスケジュールの内容です。
スケジュールの各項目は
「項目:値」の形式で指定します。

①であれば、項目がSUMMARY、値が打合せなので

SUMMARY:打合せ

と指定します。

スケジュールの項目は①~⑤を比較参照してください。

②③はそれぞれ開始日時、終了日時の項目であり
UTC時間での表記されています。
(最後に「Z」がつくとUTC時間を表す。)

例えば②は次の日時を表しています。
20181127T010000Z = 2018年11月27日 01:00:00(UTC)

日本時間はUTC+9なので
日本標準時間に設定されている
カレンダーアプリにインポートすると
下記の日時に変換されます。
2018年11月27日 10:00:00

時間の指定方法については
別の記事で紹介したいと思います。

| | コメント (0) | トラックバック (0)

2018年11月14日 (水)

Use Cells property for Range object

For referring to a certain cell
You can use both the Range property and the Cells property.

The value of cell A1 of the active sheet
can be set to 1
by the following two methods.

ActiveSheet.Range("A1") = 1
ActiveSheet.Cells(1, 1) = 1

With the Range property,
Since it must be specified in A1 format
In the For statement, the Range property is hard to use.

On the other hand, the Cells property
You can specify rows and columns with numbers
It's easy to use in For statements.

I have separately used Range properties and Cells properties
for the reasons mentioned above.

Actually,
Cells property can also be used for Range object.
See also: "Cells property" in MSDN site(Japanese only)

For example, use as follows.

Range("B2:D6").Cells(2, 2) = 2

The above code sets the value of cell C3 of the active sheet to 2.

Vba20180729a
In this usage The Cells property specifies the cell C3
at (2, 2) relative to the upper left cell
of the range of the Range object.
(The range of the Range object is
within the red frame in the above figure.)

This usage is quite useful.

Using the Cells property for the Range object,
It can be used to put values
in each cell contained in the Range object.

The number of lows and columns of the Range object
can be obtained with the following codes.

Range("B2:D6").Rows.Count
Range("B2:D6").Columns.Count

It is used for index of For statement.

Code here

Code that uses the Cells property of the Range object:

Sub macro180729a()
'How to use the Cells property
'for Range object

    Dim i As Integer, j As Integer
    Dim Rng1 As Range
   
    Set Rng1 = Range("B2:D6")
   
    For i = 1 To Rng1.Rows.Count
        For j = 1 To Rng1.Columns.Count
            Rng1.Cells(i, j) = i & ", " & j
        Next j
    Next i
   
End Sub

Result:
Vba20180729b

A value was entered in the cell of the range "B2: D6" of the range object.

| | コメント (0) | トラックバック (0)

« 2018年7月 | トップページ | 2018年12月 »