If you want to do a screen capture using VBA, (simulating the PrtScr key), you have to use:
WordBasic.SendKeys "__"
In "__" we can enter any key values. Thanks!
Welcome to VBA Tips & Tricks. All VBA related information will be posted on this blog. Of late, VBA has been disregarded by many software professionals for .Net, c# and other technologies. This blog will also post articles related to them too Happy reading
Tuesday, October 26, 2010
FileProperties
If you want to intercept the FileProperties menu command, the only reliable way to do it is to use:
Sub FileProperties()
'your code here
WordBasic.FileProperties
End Sub
In fact, if you let Word create the code for you, using the method described here, the above code will be created.
Sub FileProperties()
'your code here
WordBasic.FileProperties
End Sub
In fact, if you let Word create the code for you, using the method described here, the above code will be created.
FileCopy/FileCopyA
The VBA FileCopy statement will not copy files that are open. However, the WordBasic equivalent will (this is what is known as progress!).
The following works even if the file being copied is open:
If Left$(Application.Version, 1) = "8" Then
'Word 97
WordBasic.CopyFile FileName:="c:\OldTempDirectory\Temp1.doc", _
Directory:="C:\NewDirectory\Temp2.doc"
Else
'Word 2000 and above
WordBasic.CopyFileA FileName:="c:\OldTempDirectory\Temp1.doc", _
Directory:="C:\NewDirectory\Temp2.doc"
End If
The following works even if the file being copied is open:
If Left$(Application.Version, 1) = "8" Then
'Word 97
WordBasic.CopyFile FileName:="c:\OldTempDirectory\Temp1.doc", _
Directory:="C:\NewDirectory\Temp2.doc"
Else
'Word 2000 and above
WordBasic.CopyFileA FileName:="c:\OldTempDirectory\Temp1.doc", _
Directory:="C:\NewDirectory\Temp2.doc"
End If
ToolsBulletsNumbers
WordBasic allows you to remove all manually typed numbering from a selection using the old Word 2 command:
WordBasic.ToolsBulletsNumbers Replace:=0, Type:=1, Remove:=1
This is particularly useful for removing manually typed numbering from Headings in a document you have been emailed, prior to applying List Numbering. If you go into Outline View, set the Heading Level to the number of levels you need to remove the typed numbering from, and run the above line, it will just remove numbering from those Headings and will leave the body text alone.
WordBasic.ToolsBulletsNumbers Replace:=0, Type:=1, Remove:=1
This is particularly useful for removing manually typed numbering from Headings in a document you have been emailed, prior to applying List Numbering. If you go into Outline View, set the Heading Level to the number of levels you need to remove the typed numbering from, and run the above line, it will just remove numbering from those Headings and will leave the body text alone.
DisableAutoMacros
If you are running a macro that opens (or creates) several files, the last thing you may want is for an AutoOpen (or AutoNew) macro to fire up each time. WordBasic has a means of preventing this, which VBA never copied.
WordBasic.DisableAutoMacros 1 'Disables auto macros
WordBasic.DisableAutoMacros 0 'Enables auto macros
This command is also very useful when launching an instance of Word from another application, or from VB, when you will generally not want any AutoExec macros to fire
WordBasic.DisableAutoMacros 1 'Disables auto macros
WordBasic.DisableAutoMacros 0 'Enables auto macros
This command is also very useful when launching an instance of Word from another application, or from VB, when you will generally not want any AutoExec macros to fire
SortArray in VBA
Sub SortTest()
Dim ct(2) As String
Dim i As Long
ct(0) = "orange"
ct(1) = "apple"
ct(2) = "banana"
WordBasic.SortArray ct()
For i = 0 To 2
Debug.Print ct(i)
Next i
End Sub
Dim ct(2) As String
Dim i As Long
ct(0) = "orange"
ct(1) = "apple"
ct(2) = "banana"
WordBasic.SortArray ct()
For i = 0 To 2
Debug.Print ct(i)
Next i
End Sub
Subscribe to:
Posts (Atom)