C# Snippets


CrossReference

Public Sub Dialogs_CrossReference()
Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Sub

'http://support.microsoft.com/kb/175998
'http://support.microsoft.com/default.aspx?scid=kb;en-us;209668
With gApplicationWord.Dialogs(Word.WdWordDialog.wdDialogInsertCrossReference)
'.ReferenceType = "Figure"
'.Referencekind = Word.WdReferenceKind.wdNumberFullContext

System.Windows.Forms.SendKeys.Send("ff {TAB} {DOWN} {TAB}")
.Show()
End With

Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
End Try
End Sub

DocEvents_Close

Private Sub DocEvents_Close() Handles DocEvents2.Close

If mbFireEvents = True Then
RaiseEvent DocEventsClose_Event()
End If
End Sub

DocEvents_New

Private Sub DocEvents_New() Handles DocEvents.New

If mbFireEvents = True Then
RaiseEvent DocEventsNew_Event()
End If
End Sub

DocEvents_Open

Private Sub DocEvents_Open() Handles DocEvents.Open

If mbFireEvents = True Then
RaiseEvent DocEventsOpen_Event()
End If
End Sub

DocumentBeforeClose

Public Sub AppEvents_DocumentBeforeClose(ByVal Doc As Word.Document, _
ByRef Cancel As Boolean) _
Handles AppEvents.DocumentBeforeClose

If mbFireEvents = True Then
RaiseEvent AppEventsDocumentBeforeClose_Event(Doc, Cancel)
End If
End Sub

DocumentBeforePrint

Public Sub AppEvents_DocumentBeforePrint(ByVal Doc As Word.Document, _
ByRef Cancel As Boolean) _
Handles AppEvents.DocumentBeforePrint

If mbFireEvents = True Then
RaiseEvent AppEventsDocumentBeforePrint_Event(Doc, Cancel)
End If
End Sub

DocumentBeforeSave

Public Sub AppEvents_DocumentBeforeSave(ByVal Doc As Word.Document, _
ByRef SaveAsUI As Boolean, _
ByRef Cancel As Boolean) _
Handles AppEvents.DocumentBeforeSave

If mbFireEvents = True Then
RaiseEvent AppEventsDocumentBeforeSave_Event(Doc, SaveAsUI, Cancel)
End If
End Sub

DocumentChange

Public Sub AppEvents_DocumentChange() Handles AppEvents.DocumentChange

If mbFireEvents = True Then
RaiseEvent AppEventsDocumentChange_Event()
End If
End Sub

DocumentOpen

Public Sub AppEvents_DocumentOpen(ByVal Doc As Word.Document) _
Handles AppEvents.DocumentOpen

If mbFireEvents = True Then
RaiseEvent AppEventsDocumentOpen_Event(Doc)
End If
End Sub

Finalize

Protected Overrides Sub Finalize()
MyBase.Finalize()

gApplicationWord = Nothing
gErrorWord = Nothing
gCmdBarWord = Nothing

End Sub

Handle_Get

Public Function Handle_Get() As System.IntPtr
Dim objhandle As System.IntPtr
Dim objActiveDocument As Word.Document
Dim swindowname As String = ""
Dim bfilereadonly As Boolean = False

Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Function

If (gApplicationWord.Documents.Count > 0) Then
objActiveDocument = Document_GetActive()

swindowname &= objActiveDocument.Name
If (objActiveDocument.ReadOnly = True) Then
swindowname &= " (Read-Only)"
End If
swindowname &= " - " & gApplicationWord.Caption

objhandle = clsWin32.FindWindow("OpusApp", swindowname)
Else
swindowname &= gApplicationWord.Caption
objhandle = clsWin32.FindWindow("OpusApp", swindowname)
End If

Return objhandle

Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
End Try
End Function

InsertBreak

Public Sub Dialogs_InsertBreak()

Dim objDocument As Word.Document

Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Sub

objDocument = Document_GetActive()

If modWordObjectModel.Selection_IsProtected(objDocument) = False Then
gApplicationWord.Dialogs(Word.WdWordDialog.wdDialogInsertBreak).Show()
Else
Call modMessages.Breaks_UnableToInsertDocumentProtected()
End If

Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
End Try
End Sub

New

Public Sub New(ByVal sSolutionName As String, _
ByVal sDialogPrefix As String, _
ByVal sOfficeSolution As String, _
ByVal objWord As Word.Application, _
ByVal sVersion As String, _
ByVal objCmdBar As clsCmdBar)

Try
gApplicationWord = objWord

gsSOLUTION_NAME_WORD = sSolutionName
gsDIALOG_PREFIX_WORD = sDialogPrefix

gErrorWord = New clsError(gsSOLUTION_NAME_WORD, gsDIALOG_PREFIX_WORD, _
sOfficeSolution, objWord, sVersion)

gCmdBarWord = objCmdBar

gbDEBUG_WORD = clsError.DebugFlag("Debug Word")


Catch objCOMException As System.Runtime.InteropServices.COMException
mobjCOMException = objCOMException
Catch objException As Exception
mobjException = objException

Finally
If gbDEBUG_WORD = True Or _
((IsNothing(mobjCOMException) = False Or IsNothing(mobjException) = False)) Then

Call clsError.Handle("New", "clsWord", _
"initialise the 'clsWord' object.", _
mobjCOMException, mobjException)
End If
End Try
End Sub

NewDocument

Public Sub AppEvents_NewDocument(ByVal Doc As Word.Document) _
Handles AppEvents2.NewDocument

If mbFireEvents = True Then
RaiseEvent AppEventsNewDocument_Event(Doc)
End If
End Sub

PasteSpecial

Public Function Dialogs_PasteSpecial() As Boolean
Try
gApplicationWord.Dialogs(Word.WdWordDialog.wdDialogEditPasteSpecial).Show()
Return True

Catch ex As Exception
Return False
End Try
End Function

Quit

Public Sub AppEvents_Quit() Handles AppEvents2.Quit

If mbFireEvents = True Then
RaiseEvent AppEventsQuit_Event()
End If
End Sub

SaveFileDialog

Public Function Dialogs_SaveFileDialog() As String

Dim FileName As String = String.Empty
Dim objSaveFileDialog As New System.Windows.Forms.SaveFileDialog

Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Return "" : Exit Function

objSaveFileDialog.Filter = "Word Document (*.doc)|*.doc"
' Note: SFD owner is set to the Word Application so it is displayed on the same monitor
'If Sfd.ShowDialog(Win32Window) = System.Windows.Forms.DialogResult.OK Then
' FileName = Sfd.FileName
'End If

Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
End Try
Return FileName
End Function

Startup

Public Sub AppEvents_Startup() Handles AppEvents.Startup

If mbFireEvents = True Then
RaiseEvent AppEventsStartup_Event()
End If
End Sub

WindowActivate

Public Sub AppEvents_WindowActivate(ByVal Doc As Word.Document, _
ByVal Wn As Word.Window) _
Handles AppEvents.WindowActivate

If mbFireEvents = True Then
RaiseEvent AppEventsWindowActivate_Event(Doc, Wn)
End If
End Sub

WindowBeforeDoubleClick

Public Sub AppEvents_WindowBeforeDoubleClick(ByVal Sel As Word.Selection, _
ByRef Cancel As Boolean) _
Handles AppEvents.WindowBeforeDoubleClick

If mbFireEvents = True Then
RaiseEvent AppEventsWindowBeforeDoubleClick_Event(Sel, Cancel)
End If
End Sub

WindowBeforeRightClick

Public Sub AppEvents_WindowBeforeRightClick(ByVal Sel As Word.Selection, _
ByRef Cancel As Boolean) _
Handles AppEvents.WindowBeforeRightClick

If mbFireEvents = True Then
RaiseEvent AppEventsWindowBeforeRightClick_Event(Sel, Cancel)
End If
End Sub

WindowDeactivate

Public Sub AppEvents_WindowDeactivate(ByVal Doc As Word.Document, _
ByVal Wn As Word.Window) _
Handles AppEvents.WindowDeactivate

If mbFireEvents = True Then
RaiseEvent AppEventsWindowDeactivate_Event(Doc, Wn)
End If
End Sub

WindowSelectionChange

Public Sub AppEvents_WindowSelectionChange(ByVal Sel As Word.Selection) _
Handles AppEvents.WindowSelectionChange

If mbFireEvents = True Then
RaiseEvent AppEventsWindowSelectionChange_Event(Sel)
End If
End Sub

WindowSize

Public Sub AppEvents_WindowSize(ByVal Doc As Word.Document, _
ByVal Wn As Word.Window) _
Handles AppEvents.WindowSize

If mbFireEvents = True Then
RaiseEvent AppEventsWindowSize_Event(Doc, Wn)
End If
End Sub

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top