Windows 11 無法新增網芳印表機0x00000709,0x000006d1

win11 22H2更新導致無法連線分享印表機

Code:
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows NT\Printers\RPC]
"RpcUseNamedPipeProtocol"=dword:00000001
"RpcProtocols"=dword:00000007
"ForceKerberosForRpc"=dword:00000001

[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Print]
"RpcAuthnLevelPrivacyEnabled"=dword:00000000

fix print spooler https://www.sordum.org/9199/fix-print-spooler-v1-3/

在win10連線到win11分享之印表機,以上方法都沒用,移除所有可移除更新也都沒用,執行fix print spooler,然後新增local port印表機方式連線成功。

ms-sql–lead抓取與下筆資料日期差異天數,依群組條件(每月)重置,該月最後一筆天期計算至下月初

SELECT 
    t1.TransactionType,
    t1.TransactionDate,
    YEAR(t1.TransactionDate) AS TransactionYear,
    MONTH(t1.TransactionDate) AS TransactionMonth,
    LEAD(t1.TransactionDate, 1, DATEADD(day, 1, EOMONTH(t1.TransactionDate)))
            OVER (PARTITION BY t1.TransactionType,YEAR(t1.TransactionDate),MONTH(t1.TransactionDate) ORDER BY t1.TransactionDate) AS NextTransactionDate,
    DATEDIFF(day, t1.TransactionDate, 
        LEAD(t1.TransactionDate, 1, DATEADD(day, 1, EOMONTH(t1.TransactionDate)))
            OVER (PARTITION BY t1.TransactionType,YEAR(t1.TransactionDate),MONTH(t1.TransactionDate) ORDER BY t1.TransactionDate)) AS DifferenceInDays
FROM Transactions t1
GROUP BY 
    t1.TransactionType,
    t1.TransactionDate,
    YEAR(t1.TransactionDate),
    MONTH(t1.TransactionDate)
ORDER BY 
    t1.TransactionType,
    t1.TransactionDate;

LEAD (scalar_expression [,offset] [,default])
OVER ( [ partition_by_clause ] order_by_clause )  provides access to a row at a specified physical offset which follows the current row. It allows you to query more than one row in a SQL statement without having to join the table to itself

The  EOMONTH function in SQL is used to get the last day of the month for a specified date

DATEADD(day, 1, EOMONTH(t1.TransactionDate)) 找出月底再+1得到下月初

Excel Delete Rows Based On Criteria以巨集刪除特定條件之資料,如某欄資料空白

Sub DeleteRowsBasedOnCriteria()
    Dim ws As Worksheet
    Dim lastRow As Long
    Dim i As Long
    Dim deleteFlag As Boolean
    Dim concatenateString As String

    ' Set the active sheet as the worksheet
    Set ws = ActiveSheet

    ' Find the last row in column A
    lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row

    ' First pass: Mark rows for deletion based on the first criteria
    For i = lastRow To 1 Step -1
        ' Initialize deleteFlag to False for each row
        deleteFlag = False

        ' Check if any of the columns A through H is empty
        For j = 1 To 8 ' Columns A through H
            If ws.Cells(i, j).Value = "" Then
                ' Set the deleteFlag to True if any column is empty
                deleteFlag = True
                Exit For
            End If
        Next j

        

        ' Delete the entire row if any column A through H is empty or if the concatenation matches
        If deleteFlag Then
            ws.Rows(i).Delete
        End If
    Next i

    ' Find the last row again after the first deletion
    lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row

    ' Second pass: Delete rows based on the second criteria
    For i = lastRow To 1 Step -1
        ' Check if the concatenation of the first 9 columns equals a specific string
        concatenateString = ""
        For j = 1 To 9 ' Columns A through I
            concatenateString = concatenateString & ws.Cells(i, j).Value
        Next j

        ' Delete the entire row if the concatenation matches the specific string
        If concatenateString = "訂單號碼訂單日預定出港日品名台灣品名數量/KGS包裝方式目的地備註" Then
            ws.Rows(i).Delete
        End If
    Next i
End Sub

Powershell script透過outlook每日發送刷卡資料

新增powershell script 檔案sendmail2.ps1 內容如:

$From = "0420@company.com.tw"
$To = "0420@company.com.tw","11010@company.com.tw","0260@company.com.tw","0410@company.com.tw"
$Subject = "card datas - $(Get-Date -Format 'yyyy-MM-dd')"
$Body = "card datas"
$AttachmentPath = "H:\RecData.txt"  # Specify the path to your attachment

Send-MailMessage -From $From -To $To -Subject $Subject -Body $Body -SmtpServer "192.168.x.x" -Attachments $AttachmentPath

新增工作排程 啟動程式 powershell.exe 新增引數-ExecutionPolicy Bypass -File ” C:\Users\user31\Desktop\sendmail2.ps1″

郵件未通過IP反解驗證被視為垃圾郵件

使用者反應某廠商無法收到公司寄出e-mail,進一步了解原因為公司沒做反解,請ISP設定後,對方可正常收信。

正解/反解 的設定對象為何

●正解需求的設定對象:為網址的擁有者,因此是去DNS Server 那設定。
●反解需求的設定對象:有權限的ISP。

TWNIC僅提供網域名稱設定對應IP位址的解析服務,如果您需要設定以IP反解網域名稱的服務,請向您申請IP的ISP公司洽詢。

在Excel 2013 檔案中,點選滑鼠右鍵,未出現右鍵功能選單,但在其他程式Word、Outlook皆正常(right-click menu is missing in excel)

1.在工作表的地方按 ALT + F11

2.再按 Ctrl+G 會出現一欄及時運算

3.複製貼上以下程式碼

Application.CommandBars(“Cell”).enabled=True

Application.CommandBars(“Cell”).Reset

4.按Enter

5.按 Alt+Q 回到工作表

https://groups.google.com/g/microsoft.public.excel.misc/c/rlvcJrM_JE8?pli=1

Right Click on Column or Row does not show Context Menu

application.CommandBars(“Cell”).Reset
application.CommandBars(“cell”).Enabled = True
application.CommandBars(“Column”).Reset
application.CommandBars(“column”).Enabled = True
application.CommandBars(“Row”).Reset
application.CommandBars(“row”).Enabled = True

press enter every command

https://superuser.com/questions/360399/right-click-on-column-or-row-does-not-show-context-menu

Excel VBA用SQL語法找出生產報工資料員工每日最早一筆報工開始與最晚一筆報工結束做工時統計,資料來源為自己的寫法.

chatgpt提醒Make sure to add a reference to the “Microsoft ActiveX Data Objects” library in your VBA project by going to “Tools” > “References” and checking the appropriate version (e.g., “Microsoft ActiveX Data Objects x.x Library”). 實測office2010 選用 2.8 library是可行。

Sub GetGroupedData()
    ' Define variables
    Dim wsResult As Worksheet
    Dim wsSource As Worksheet
    Dim rngSource As Range
    Dim rngResult As Range
    Dim strSQL As String
    Dim connString As String
    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim rowIndex As Long
    Dim colIndex As Long
    Dim strSourceRng As String
    ' Set the source worksheet
    Set wsSource = ThisWorkbook.Worksheets("Sheet1")
    
     Dim lastRow As Long
    lastRow = wsSource.Cells(wsSource.Rows.Count, 1).End(xlUp).Row
    
    strSourceRng = Trim("[Sheet1$A1:F" + Trim(Str(lastRow)) + "]")
        
    ' Check if the result sheet already exists
    On Error Resume Next
    Set wsResult = ThisWorkbook.Worksheets("Result")
    On Error GoTo 0
    
    ' If the result sheet exists, clear its contents
    If Not wsResult Is Nothing Then
        Application.DisplayAlerts = False
        wsResult.Cells.Clear
        Application.DisplayAlerts = True
    Else
        ' If the result sheet doesn't exist, create it
        Set wsResult = ThisWorkbook.Worksheets.Add
        wsResult.Name = "Result"
    End If
    
    ' Define the range where the result will be displayed
    Set rngResult = wsResult.Range("A1")
    
    ' Connection string (Excel version-dependent)
    connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.FullName & ";" & _
                 "Extended Properties=""Excel 12.0 Xml;HDR=YES"";"
    
    ' SQL query to retrieve the grouped data
    'strSQL = "SELECT col1, col2, col3, col4, MIN(col5) AS MinValue, MAX(col6) AS MaxValue FROM [Sheet1$A1:N274] " & _
             "GROUP BY col1, col2, col3, col4"
    
    strSQL = "SELECT col1, col2, col3, col4, MIN(col5) AS MinValue, MAX(col6) AS MaxValue FROM " & strSourceRng & _
             "GROUP BY col1, col2, col3, col4"
    'wsSource.Range("N3").Value = strSQL
    
    ' Create a connection object
    Set cn = New ADODB.Connection
    
    ' Open the connection
    cn.Open connString
    
    ' Create a recordset object
    Set rs = New ADODB.Recordset
    
    ' Execute the query and populate the recordset
    rs.Open strSQL, cn
    
    ' Write the column headers to the result range
    For colIndex = 1 To rs.Fields.Count
        rngResult.Offset(0, colIndex - 1).Value = rs.Fields(colIndex - 1).Name
    Next colIndex
        rngResult.Offset(0, colIndex - 1).Value = "時數(HR)"
    ' Write the data to the result range
    rowIndex = 1
    Do Until rs.EOF
        For colIndex = 1 To rs.Fields.Count
            rngResult.Offset(rowIndex, colIndex - 1).Value = rs.Fields(colIndex - 1).Value
        Next colIndex
               ' Convert col5 and col6 to DateTime values
        Dim dt1 As Date
        Dim dt2 As Date
        dt1 = CDate(rs.Fields("MinValue").Value)
        dt2 = CDate(rs.Fields("MaxValue").Value)
        
        ' Calculate the difference and add as col7
        Dim diff As Double
        diff = dt2 - dt1
        rngResult.Offset(rowIndex, rs.Fields.Count).Value = Round(diff * 24, 2)
        
        rs.MoveNext
        rowIndex = rowIndex + 1
    Loop
    
    ' Clean up
    rs.Close
    cn.Close
    Set rs = Nothing
    Set cn = Nothing
    
    ' Format the result range as desired
    
    ' Optional: Autofit columns in the result range
    wsResult.Columns.AutoFit
End Sub
其中組合SQL語法from 片段時原本程式碼為
 ' Set the name of the sheet containing the data
    sheetName = "Sheet1"
    
    ' Set the range of data in Sheet1
    Set rngData = ThisWorkbook.Worksheets(sheetName).UsedRange
  
    ' SQL query to retrieve data from Sheet1
    strSQL = "SELECT * FROM [" & sheetName & "$" & rngData.Address & "]"
會有錯誤才改成自行抓取最後一筆,手動組成範圍。
原本不使用VBA與SQL語法,單純用excel Function來做
1.手動找出distinct的 上班日、員工代號、姓名、報工別
2.將上下工時間由字串改成日期時間 =DATEVALUE(上工時間) + TIMEVALUE(上工時間),這樣才能做運算,算出時數。
3.=MAX(IF((A:A=L2)*(B:B=M2)*(D:D=O2),I:I)) 找出MAX值
  =MIN(IF((A:A=L2)*(B:B=M2)*(D:D=O2),H:H)) 找出MIN值
  其中L、M、O欄位第1.步驟抓出之distinct值 A、B、D為原始資料
4.Instead of pressing Enter, use Ctrl+Shift+Enter to enter the formula as an array formula. This will enclose the formula in curly braces {} and calculate the distinct values based on the three columns
5.差異為=(MAX-MIN)*24 

WIN11 + EpsonLQ-680連線問題排除

舊配置 AMD文書機 win10 home +USB延長線+USB 轉LPT port+LQ-680可正常列印

新配置主機換成DELL i5-12400 + win11 home 一樣連線方式,卻發生列印幾張後即中斷、列印任務卡住等異常。

問題排除一:假設-USB延長線生鏽或接觸不良導致。實作-改用USB Printer server連線方式,win11 home+網路+USB Printer server+USB 轉LPT port+LQ-680,狀況一樣,連續列印會中斷。

問題排除二:假設-USB 轉LPT port轉接線異常。實作-改用LPT Printer server 連線方式,win11 home+網路+LPT Printer server+LQ-680,狀況一樣。

問題排除三:假設-軟體或設定導致。實作-於印表機內容連接埠設定由LPR改成RAW,問題終於排除。觀測印表機工作佇列,RAW會一下子吃掉所有工作,LPR則會一個一個慢慢執行。運作模式不同而導致結果不同。

狀況二:隔週使用者反映印表機又無法使用啦!!!

問題排除四:假設-於排除三運作模式已確認可行,應為其他硬體問體導致。實作-ping printer server發現無法ping通,重啟printer server也無法ping通,換一條網路線就可以通了,此時使用者發現原來網路線被折彎,導致有個角度才會通。

總結:由於此為外點之設備,無法直接實機檢測與排除,遠端遙控使用者操作增加異常排除難度與時程拖長,期間使用者抱怨無法使用,只有耐心溝通,按照假設一步步實作,終於解決。觀察點一:原本舊機+win10直連方式換成新機+win11卻無法正常運作,還是不知原因,因為直連不須也無法設定連接埠。觀察點二:連接埠LPR與RAW運作模式之差異,導致實際使用結果不同,這兩種模式之差異與適用時機為何?

EXCEL分欄列印–一頁印原兩頁資料

Step1.首先選取Excel中要列印的部分,並按下功能表的【編輯】→【複製】。
Step2.開啟Word程式,打開一個新文件後,按下功能表的【編輯】→【貼上】。
Step3.貼上從Excel複製過來的欄位內容後,繼續在Word裡點選功能表的【格式】→【欄】。
Step4.在「欄」對話盒裡,選取要分割的欄位數量後,按下〔確定〕。
Step5.接著選取第一列,並按下功能表的【表格】→【跨頁標題重複】。
Step6.最後可以看到Word中的每一欄表頭,都會出現標題列,這樣就能把Excel裡的資料做分欄列印了。

寄信到gmail被退信,DNS新增SPF紀錄可解決

錯誤訊息

Remote server replied: 550-5.7.26 This mail is unauthenticated, which poses a security risk to the

550-5.7.26 sender and Gmail users, and has been blocked. The sender must

550-5.7.26 authenticate with at least one of SPF or DKIM. For this message, 550-5.7.26 DKIM checks did not pass and SPF check for

今天終於拿到DNS管理帳密,登入twnic找到DNS管理,新增一筆 TXT紀錄
Value: v=spf1 ip4:192.168.x.x 如下圖(此ip為對外發信實體IP),這樣就解決啦。

參考 https://openfind.zendesk.com/hc/zh-tw/articles/5336499446159-SPF-%E8%A8%AD%E5%AE%9A%E6%96%87%E4%BB%B6

https://support.google.com/a/answer/10685031?sjid=15193580675983634622-AP