Sub CsvImport001Management02()
'インポート CSV(UTF-8)
'項目にカンマ・改行が含まれているデータ
Dim i As Integer
Dim ado_strem As New ADODB.Stream
Dim strLine As String, strLine2 As String
Dim tmp As Variant, tmp2 As Variant
Dim canma As String
Dim colName(20) As String
'File変数
Dim filePath As String
filePath = "C:\Users\shiba\My\プログラム言語\ACCESS\基準.csv"
canma = ","
With ado_strem
.Charset = "UTF-8"
.Mode = 3 '1:読み取り専用 3:読み取り/書き込み両方
.Type = adTypeText '1:バイナリデータ 2:テキストデータ 0:不明(規定値)
.LineSeparator = 10 '改行コード 10:LF 13:CR -1:CRLF(規定値)
.Open
.LoadFromFile (filePath)
'列取得 すべてのデータを読み込むには「-1」を指定し、1行ずつ読み込むときは「-2」を指定
strLine = .ReadText(-2)
strLine = Replace(strLine, """", "")
tmp = Split(strLine, ",")
For i = LBound(tmp) To UBound(tmp)
colName(i) = tmp(i)
Next i
'データ読込
Do While Not (.EOS)
strLine = .ReadText(-2)
'セルの改行対策
Do
If Right(strLine, 1) <> """" Then
strLine2 = .ReadText(-2)
strLine = strLine & strLine2
Else
Exit Do
End If
Loop
'最初のデータの「"」以降を取り除く
strLine = Right(strLine, Len(strLine) - 1)
'最後のデータの「"」以降を取り除く
strLine = Left(strLine, Len(strLine) - 1)
'","で分割
tmp = Split(strLine, """" & canma & """")
For i = LBound(tmp) To UBound(tmp)
' colName(i) = tmp(i)
Debug.Print tmp(0) & ":" & tmp(1) & ":" & tmp(2)
Next i
i = i + 1
Loop
.Close
End With
End Sub
【PiowerApps】Office365Users
With( {
fullName:Split(User().FullName," ")
},
Last(fullName).Value &" "& First(fullName).Value & " さん"
)
User().Email
//T_勤務管理から該当ユーザー・該当月のデータを全て取得する
ClearCollect(colWorkTable, Filter(T_勤務管理,User().Email = メールアドレス, Text(_firstDayOfMonth, "yyyy/mm") = Text(就業日, "yyyy/mm")));
Set(gblMailWAS,colWorkTable.メールアドレス);
Set(gblUserWAS,colWorkTable.ユーザー名);
Set(gblOnsiteDateWAS,Concat(colWorkTable, ThisRecord.就業日 & "," & Char(13)));
//メッセージ送信フロー実行
メッセージ送信.Run(gblMail,gblUser,gblOnsite_date);
【PwerApps】複合検索 Search・Filter
■コンボボックス
Items:colCategory
■テキスト
Default:“”
■ギャラリー
コンボボックスが空白の場合、データは全部表示
コンボボックスまたはテキストで検索したデータを表示
其々に値がある場合、複合も可
//コンボボックス検索
Sort(
Search(
If(
IsBlank(cmbSearchNameMCS.SelectedItems) = true || IsEmpty(cmbSearchNameMCS.SelectedItems) = true,
colItem,
Filter(
colItem,
CategoryId in cmbSearchNameMCS.SelectedItems.CategoryId
)
)
,
txtSearchNameMCS.Text,
"ItemName"
),ItemId
)
■ギャラリー
テキストが空白(で始まる)の場合、データは全部表示
テキストにデータがある場合、日付範囲内データを表示
If(
IsBlank(txtSelectWAMS.Text) = true,
T_勤務管理,
Filter([@T_勤務管理],
dteStartDayQAMS.SelectedDate <= 就業日 && dteEndtDayQAMS.SelectedDate >= 就業日,
StartsWith(ユーザー名,txtSelectWAMS.Text)
)
)
【VBA】ファイルコピー
ローカルファイル保存先
ファイル保存先
ファイル名
済 パス
Option Explicit
'sheet
Dim reSh As Worksheet
Dim wrSh As Worksheet
Dim rebk As Workbook
Dim wrbk As Workbook
'Cells
Dim wrRow As Long
Dim wrCol As Integer
Dim reRow As Long
Dim reCol As Integer
'file
Dim shName As String
Dim fileName As String
Dim filePath As String
Dim sourceFileName As String
Dim destFileName As String
'ファイルパスからモジュールを抽出しモジュールフォルダにテキストファイルを作成
Sub ChangMacroToTextList()
Dim localFolderPath As String
Dim destFolderPath As String
Dim keyFileName As String
Dim destFileName As String
Dim recFlg As Boolean
Set wrbk = ThisWorkbook
Set wrSh = wrbk.Worksheets("ファイルコピー")
wrCol = 2
wrRow = 1
localFolderPath = wrSh.Cells(wrRow + 1, wrCol)
destFolderPath = wrSh.Cells(wrRow + 2, wrCol)
keyFileName = wrSh.Cells(wrRow + 3, wrCol)
'フォルダ作成
Call CreateFolder(localFolderPath)
wrCol = 2
wrRow = 10
With wrSh
Do While .Cells(wrRow, wrCol) <> ""
destFileName = GetLocalTime
'ファイルコピー
recFlg = CopyFileWildCardD(.Cells(wrRow, wrCol), localFolderPath & "\" & argDestFileName, keyFileName)
If recFlg = True Then
.Cells(wrRow, wrCol - 1) = "済"
End If
wrRow = wrRow + 1
Loop
End With
'フォルダ作成
Call CreateFolder(localFolderPath)
'フォルダコピー
Call CopyFolderOne(localFolderPath, destFolderPath)
Set wrSh = Nothing
End Sub
'ファイルコピー
Function CopyFileWildCardD(argTargetFilePath As Variant, argDestFilePath As Variant, argKeyFileName As Variant) As Boolean
fileName = Dir(argTargetFilePath & "\" & argKeyFileName)
CopyFileWildCard = False
If fileName <> "" Then
Call CopyFile(argTargetFilePath & "\" & fileName, argDestFilePath)
CopyFileWildCard = True
End If
End Function
<mdl共有>
Option Explicit
'False/True
Public Const RETURN_FALSE = False
Public Const RETURN_TRUE = True
'GetLocalTime(Win32API)
Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
'// 64bit版
#If VBA7 And Win64 Then
Declare PtrSafe Sub GetLocalTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
'// 32bit版
#Else
Declare Sub GetLocalTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
#End If
'sheet
Dim reSh As Worksheet
Dim wrSh As Worksheet
Dim rebk As Workbook
Dim wrbk As Workbook
'Cells
Dim wrRow As Long
Dim wrCol As Integer
Dim reRow As Long
Dim reCol As Integer
'file
Dim shName As String
Dim fileName As String
Dim filePath As String
Dim sourceFileName As String
Dim destFileName As String
Function GetLocalTime() As String
Dim sysTime As SYSTEMTIME
Dim setTime
'//現在日時取得
Call GetLocalTime(sysTime)
'//yyyymmdd_hhmmssffに整形
setTime = Format(sysTime.wYear, "0000")
setTime = setTime & Format(sysTime.wMonth, "00")
setTime = setTime & Format(sysTime.wDay, "00")
setTime = setTime & "_"
setTime = setTime & Format(sysTime.wHour, "00")
setTime = setTime & Format(sysTime.wMinute, "00")
setTime = setTime & Format(sysTime.wSecond, "00")
setTime = setTime & Format(sysTime.wMilliseconds, "00")
Debug.Print setTime
GetLocalTimeTest = CStr(setTime)
End Function
'ファイルコピー
Function CopyFileWildCard(argTargetFilePath As Variant, argDestFilePath As Variant, argKeyFileName As Variant) As Boolean
fileName = Dir(argTargetFilePath & "\" & argKeyFileName)
CopyFileWildCard = False
If fileName <> "" Then
Call CopyFile(argTargetFilePath & "\" & fileName, argDestFilePath)
CopyFileWildCard = True
End If
End Function
'ファイルコピー
Sub CopyFile(argTargetFilePath As Variant, argDestFilePath As Variant)
Dim objFso As New FileSystemObject
With objFso
'元ファイルが無い場合、EXIT
If (.FileExists(argTargetFilePath) = True) Then
Exit Sub
End If
'ファイルをコピー
.CopyFile argTargetFilePath, argDestFilePath
End With
End Sub
'新規フォルダ作成
Function CreateFolder(argFolderPath As String) As Boolean
On Error GoTo ERROR_1
Dim objFso As New FileSystemObject
'フォルダが存在しない
With objFso
If (.FolderExists(argFolderPath) = False) Then
'フォルダ作成
.CreateFolder (argFolderPath)
End If
End With
CreateFolder = RETURN_TRUE
Exit Function
ERROR_1:
CreateFolder = RETURN_FALSE
MsgBox "CreateFolderでエラーが発生しました エラー番号=" & Err.Number & Chr(13) & _
"エラーの内容は「" & Err.Description & "」です。"
End Function
'ファイルを一括でコピー
'引数:CopyFileAll(フォルダーパス & "\*.csv", フォルダーパス)
Sub CopyFileAll(argTargetWildFilePath As Variant, argDestFolderPath As Variant)
Dim objFso As New FileSystemObject
With objFso
'ファイルを一括でコピー
objFso.CopyFile argTargetWildFilePath, argDestFolderPath
End With
End Sub
'フォルダ コピー
'Call objFso.CopyFolder(argTargetPath, "D:\TipsCopy", True)
'フォルダ名を指定してコピー
'Call objFso.CopyFolder("D:\TipsFolder", "D:\ParentFolder\", True)
'同じフォルダ名でコピー (D:\ParentFolder\TipsFolder)
Sub CopyFolderOne(argTargetPath As Variant, argDestPath As Variant)
Dim objFso As New FileSystemObject
Dim targetPath As String
Dim destPath As String
targetPath = argTargetPath
destPath = argDestPath
With objFso
If (.FolderExists(destPath) = True) Then
If MsgBox("既存のフォルダを削除しますか?", vbOKCancel) = 1 Then
.DeleteFolder destPath
End If
End If
'フォルダ名を指定してコピー
.CopyFolder targetPath, destPath & "\"
End With
End Sub
WinActor TIPS
WinActorノード命名
入力「社員コード」
入力「社員コード=00001」
クリック「社員コード」
キー送信「Enter」
マッチング「」
状態「」
「サブシナリオ」呼び出し
★TIPS
文字列入力(WIN32)で入力しても、値は入力されるがシステムの動作上、うまく機能しないことがある。その場合
クリック(WIN32)>エミュレーションで文字送信
*「エミュレーションで文字送信」は英数字のみ有効なため、それ以外の場合、文字列送信を使用する。記号が入っている場合、記号は自動的に除外される。
例:20.03.01→200301
★TIPS
・WEBのセッション切れ防止
見た目の変化に影響を受けにくい「エミュレーション」で[F5]キーを押下する操作(更新)
・ループの前に「ウィンドウ識別クリア」
・WinActorのウィンドウ識別は識別ルールに合致するウィンドウのうち一番手前にあるウィンドウを対象にとる
・ウィンドウ識別名を「(スクリーン)」に設定することで、その時点でアクティブなウィンドウに対してエミュレーションやノード「画像マッチング」の操作を行うことができる
★BAT
・起動
WinActorパス -f シナリオパス -d CSVファイル -r -e -t
C:\XXX\WinActor\WinActor.exe -f "C:\programs\WinActor\scenarios\TIMEPRO時刻同期.ums6" -d "XXX.CSV" -r -e -t
appPath = “””” & .Range(“A1”) .Value & “\WinActor.exe” & “””” & “ –f ” & __
“””” & .Range(“A2”).Value & “\” & exeFileName & “””” & –d ” & __
“””” & .Range(“A1”) .Value & “\” & csvFileName & “””” & “–r –t -e ” & __
・終了
taskkill /f /t /im winactor.exe
【PowerShell】呼び出し方 file_copy
file_copy.bat
@echo off
cd C:/Users/xxxxx/Desktop/ps
powershell -NoProfile -ExecutionPolicy Unrestricted ./file_copy.ps1
echo 完了しました!
pause > nul
exit
file_copy.ps1 - ショートカット
リンク先
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy RemoteSigned -File C:\Users\xxxxx\Desktop\ps\file_copy.ps1
リンク先の前に「powershell -ExecutionPolicy RemoteSigned -File」を付ける。