Enumap's Weblog

20110707

Libre/Open Office; Macro: Check Sheet Name is Exist?

Filed under: Libre/Open Office — enumap @ 99:23 am

20110707

“วันนี้คณะวิศวฯ จุฬาฯ รับปริญญา”

การเขียนมาโครใน Libre Office หรือ Open Office มีหลายภาษาในที่นี้ใช้ VBA เพราะเคยทำมาบ้างใน Excel คำสั่งทั่วไปเหมือนกันจะได้ไม่ต้องเรียนรู้ใหม่มาก ที่ต่างกันคือการเรียกฟังก์ชั่นภายใน หรือเรียกคอมโพเนนท์ของ  Libre/Open Office ที่สำคัญตามหายากหน่อยว่าเรียกว่าอะไร พอทำไว้ได้ก็ต้องเอามาแปะไว้ต้องการเมื่อไหร่จะได้มาหา และเป็นการแบ่งปันผู้ที่ยังไม่รู้ ให้เข้าถึงความรู้ได้เร็วขึ้น

Check Sheet Name is Exist?

this script for CALC
ใช้สำหรับโปรแกรม CALS เป็นการตรวจสอบว่า ชีทในชื่อที่กำหนดนี้มีหรือยัง ฟังดูเหมือนง่ายนะครับแค่ดูก็เห็นแล้วว่ามีหรือไม่ แต่ทำยังไงให้เครื่องรู้ลองหลายวิธี หาโค้ทเก่าที่ทำบน Excel มาปรับปรุงสุดท้ายก็ใช้ได้ มาดูกันเลย

อ้างอิงตัวอย่างจากกระทู้นี้ (referent:http://www.ozgrid.com/forum/showthread.php?t=40992&page=1)

Function bWorksheetExists(WSName As String) As Boolean
    On Error Resume Next
    bWorksheetExists = (ThisComponent.Sheets.getByName(WSName).getname = WSName)
End Function

Sub ChectTab()
	inputTab = "Sheet2"'
	If Not bWorksheetExists(inputTab) Then
         'Sheet does not exist
         'do something
         Msgbox(inputTab & " does no exist")
    Else
         'Sheet exists
         Msgbox(inputTab & " exist")
    End If

End Sub

จะนำไปใช้เพิ่มเติมยังไงก็แล้วแต่จะพัฒนาต่อนะครับ ^_^
Advertisement

1 Comment »

  1. เข้า google มาหาเรื่อง python อ่าน
    แต่มาเจอบทความ python ในบอร์ดนี้
    อ่านไปอ่านมา เอ๊ะ ENU นี่คุ้น ๆ เห็นรูปก็ยังไม่แน่ใจ

    นั่งอ่านไปเรื่อย ๆ

    อ้าวพี่ภานุนี่เอง …

    เขียนดีมากเลยครับพี่ ไว้จะเข้ามาตามอ่านเรื่อย ๆ นะ

    ขอบคุณครับ

    หนุ่ม

    NU

    Comment by Noom — 20110710 @ 1111:06 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.