การเปิดไฟล์ *.dot ของ Word แล้ว Run มาโครด้วย
กระทู้เก่าบอร์ด อ.สุภาพ ไชยา

 248   1
URL.หัวข้อ / URL
การเปิดไฟล์ *.dot ของ Word แล้ว Run มาโครด้วย

ถามไว้ที่
http://www.quicktechusa.com/msgboard/wwwboard.pl?read=17558

คำถามเขามีดังนี้

Dim myappid
Dim WordMac As String

If (Forms!frmLetters!cmbLetterSelection = "Full Application Letter (Staying Put)" And Forms!frmLetters!TYPE = "HRA") Then

' Select Word HRA1 Macro
WordMac="winword.exe /n /l\\computers\sys\health\access97\grants\grants.dot"
myappid = Shell(WordMac, 1)
WordMac = "winword.exe /mhra1"
myappid = Shell(WordMac, 1)
AppActivate myappid
End If

this is the coding i use, which runs fine from access 97 to word 97, the error message I keep getting is "file not found"
thanks

คือ เขาใช้โค้ดข้างบนกับ Word 97 ได้ แต่ไม่สามารถใช้ได้กับ Word 2K ได้ โดยฟ้องว่า "file not found"

ผมลองทำตามโค้ดของเขาดู ปรากฏว่า Shell() เป็นตัวก่อปัญหา คือ มันจะไม่เข้าใจชื่อไฟล์หรือโฟล์เดอร์ที่ยาวๆ หรือที่มีช่องว่างด้วย ซึ่งผมเคยเจอคนถามปัญหาเกี่ยวกับการใช้ Shell() บ่อยมาก

ผมจะใช้โค้ดข้างล่าง เพื่อให้ทำงานได้เหมือนที่เขาต้องการครับ

Sub OpenTemplate()
Dim objWord As Object
Dim strFileName As String
strFileName = "D:\Program Files\Microsoft Office\Templates\1054\Elegant Report.dot"
Set objWord = CreateObject("Word.Application")
With objWord
.Visible = True
.Documents.Open FileName:=strFileName
.Run MacroName:="ShowFont"
End With
MsgBox "Finished"
objWord.Quit
Set objWord = Nothing
End Sub


1 Reply in this Topic. Dispaly 1 pages and you are on page number 1

1 @R06512
   
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.0535s