0% found this document useful (0 votes)
9 views

Function Create

This function automates the creation of a new sheet in Excel. It uses mouse movements and clicks to navigate the interface, copy and paste values between sheets, and enter text. Key steps include: 1. Getting the target sheet name from a cell and copying it to a temporary sheet. 2. Repeatedly attempting to create the new sheet by clicking buttons and entering the name, checking after each attempt if it was successful. 3. If unsuccessful after 15 tries, it marks the attempt as failed in a log. Otherwise, it completes the sheet creation process and returns a value.

Uploaded by

jplay1208
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Function Create

This function automates the creation of a new sheet in Excel. It uses mouse movements and clicks to navigate the interface, copy and paste values between sheets, and enter text. Key steps include: 1. Getting the target sheet name from a cell and copying it to a temporary sheet. 2. Repeatedly attempting to create the new sheet by clicking buttons and entering the name, checking after each attempt if it was successful. 3. If unsuccessful after 15 tries, it marks the attempt as failed in a log. Otherwise, it completes the sheet creation process and returns a value.

Uploaded by

jplay1208
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Function Create_NewSheet(RowVal As Variant, NewX As Variant, NewY As Variant,

PNX As Variant, PNY As Variant, TempA1X As Variant, TempA1Y As Variant, ShiftX As


Variant, RemarkX As Variant, RemarkY As Variant, NoChangeX As Variant, NoChangeY
As Variant)
create_new:
'絋粄穝糤 Θ狡籹珇腹ず甧絋粄
GetPNVal = "0"
PNval = Worksheets("跑戈").Range("C" & RowVal).Value
Worksheets("Temp").Range("A1").Value = "0"
Worksheets("Temp").Range("A1").Copy
Worksheets("Temp").Range("A1").PasteSpecial Paste:=xlPasteValues
Iteration = 0
Do While GetPNVal <> PNval And Iteration < 15
Iteration = Iteration + 1
'穝糤虫沮
SetCursorPos NewX, NewY
DoEvents
Sleep 50
Call 虫阑
DoEvents
Sleep 50
'块珇腹
SetCursorPos PNX, PNY
DoEvents
Sleep 50
Call 虫阑
DoEvents
Sleep 50
Call オ龄
DoEvents
SetCursorPos PNX - ShiftX, PNY
DoEvents
Sleep 100
Call 秨オ龄
DoEvents
Sleep 100
SetCursorPos PNX, PNY
DoEvents
Sleep 50
Call オ龄
DoEvents
SetCursorPos PNX + ShiftX, PNY
DoEvents
Sleep 100
Call 秨オ龄
DoEvents
Application.SendKeys PNval '块珇腹
DoEvents
Sleep 50
'翴阑称猔
SetCursorPos RemarkX, RemarkY
DoEvents
Call 虫阑
DoEvents
Sleep 50
'浪琩ぃゼ絋粄跑虫
SetCursorPos NoChangeX, NoChangeY
DoEvents
Sleep 100
GetMouse
ErrorFlag = Worksheets("公夹 Г 夹砞竚").Range("C1").Value
Worksheets("公夹 Г 夹砞竚").Range("C1").ClearContents
If ErrorFlag = "OK" Then
NewOK = 0
SetCursorPos NoChangeX, NoChangeY
DoEvents
Call 虫阑
DoEvents
Sleep 50
'斌纗郎
Worksheets("跑戈").Range("G" & RowVal).Value = "ゼ絋粄跑虫"
SetCursorPos AbortX, AbortY
DoEvents
Call 虫阑
DoEvents
Sleep 50
'翴阑絋粄斌
SetCursorPos ConfirmAbortX, ConfirmAbortY
DoEvents
Call 虫阑
DoEvents
GoTo exit_create
Else
NewOK = 1
End If

'狡籹珇腹
SetCursorPos PNX, PNY
DoEvents
Sleep 50
Call 虫阑
DoEvents
Sleep 50
Call オ龄
DoEvents
SetCursorPos PNX - ShiftX, PNY
DoEvents
Sleep 100
Call 秨オ龄
DoEvents
Sleep 100
SetCursorPos PNX, PNY
DoEvents
Sleep 50
Call オ龄
DoEvents
SetCursorPos PNX + ShiftX, PNY
DoEvents
Sleep 100
Call 秨オ龄
DoEvents
Application.SendKeys ("^c") '狡籹珇腹
DoEvents
Sleep 100
'耞芭禟茂ず甧琌フ
ClipFormat = Excel.Application.ClipboardFormats
If UBound(ClipFormat) = 1 And ClipFormat(1) = -1 Then
'芭禟茂礚ず甧
Worksheets("Temp").Range("A1").Value = "0"
GetPNVal = "0"
Else
Worksheets("Temp").Select
Worksheets("Temp").Range("A1").Select

SetCursorPos TempA1X, TempA1Y


DoEvents
Call 虫阑
DoEvents
Sleep 50
Worksheets("Temp").Paste '狡籹珇腹
GetPNVal = Worksheets("Temp").Range("A1").Value
GetPNVal = CStr(GetPNVal)
End If
Set ClipFormat = Nothing
Loop
If GetPNVal <> PNval Then
'MsgBox ("穝糤虫ア毖")
Worksheets("跑戈").Range("G" & RowVal - 1).Value = "Failed"
'翴阑厨牡埃
SetCursorPos NoChangeX, NoChangeY
DoEvents
Call 虫阑
DoEvents
Sleep 50
'翴阑斌
SetCursorPos AbortX, AbortY
DoEvents
Call 虫阑
DoEvents
Sleep 50
Stop
GoTo create_new
End If
Worksheets("Temp").Range("A1").ClearContents
'块称猔
SetCursorPos RemarkX, RemarkY
DoEvents
Sleep 50
Call 虫阑
DoEvents
Sleep 50
Call 蛮阑
DoEvents
Sleep 50
Application.SendKeys "AutoUpdate" '块称猔
DoEvents
Sleep 100

exit_create:
Create_NewSheet = NewOK
End Function

You might also like