VBA Groupwise Email - vba

I'm using Excel 2013, Windows 7, Groupwise 12.
The code should be pretty straight forward, but I keep getting an error
"Active X component can't create object"
I've made sure the references are there according to the Groupwise's development documents which is simply their "gwcma1.dll" and I just can't figure out what is going on.
Theory right now is that Groupwise was installed some way that didn't populate the registry information needed for the code to create the object even though it is in the object browser.
Code:
Dim gwAccount As GroupwareTypeLibrary.Account2
Set gwApp = CreateObject("NovellGroupwareSession")
I've used this code for years on older versions of excel and windows and groupwise, and I can't figure out what has changed.
---EDIT---
Here's the beginning part of the code. After this is just standard loops and logic that all works.
Here's the first part of it. After this point, it's just standard loops and and logic.
Sub EmailPDFs()
Dim i, k As Long
Dim PhysicianCount As Long
Dim StartPoint As Long
Dim CurrentNPI As Long
Dim CurrentEmail As String
Dim CurrentFileName As String
Dim CurrentFilePath As String
Dim CurrentDate As String
Dim EmailBody As String
'Declaration for Email
Dim gwMessage As GroupwareTypeLibrary.Message2
Dim gwAccount As GroupwareTypeLibrary.Account2
Dim gwApp As GroupwareTypeLibrary.Application
Set gwApp = CreateObject("NovellGroupwareSession")
Set gwAccount = gwApp.Login()
---EDIT 2---
I tried Application2 and still the same error. I think I was trying the older one and the properties were the same on the object, but Application2 let you do proxy email access which I wasn't worried about.
For creating a new application, I may need a refresh on the syntax but I'm assuming you're suggesting something like:
Dim xlApp as Excel.Application
Set xlApp = New Excel.Application 'Early Binding
Set xlApp = CreateObject(“Excel.Application”) 'Late Binding

Related

Excel VSTO - Hide multiple columns lambda function issue - VB.NET

I've been trying to figure out what is wrong with my code below, but no success so far.
My simple task is to hide multiple Excel columns using VSTO / VB.NET.
This works:
Dim app As Excel.Application = Globals.ThisAddIn.Application
Dim act_sheet As Excel.Worksheet = app.ActiveSheet
act_sheet.Range("A:A").EntireColumn.Hidden = True
act_sheet.Range("B:B").EntireColumn.Hidden = True
This doesn't work:
Dim app As Excel.Application = Globals.ThisAddIn.Application
Dim act_sheet As Excel.Worksheet = app.ActiveSheet
Dim base_hide As New List(Of String)({"A:A", "B:B"})
base_hide.ForEach(Function(x) act_sheet.Range(x).EntireColumn.Hidden = True)
I get no errors compiling it, the string address is taken correctly. Any idea?
Thank you,
C
Found what caused the issue. Running a ForEach loop as lambda with Function() would expect to return something. My code inside the function never run. Changing it to Sub() works as expected.
base_hide.ForEach(Sub(x) act_sheet.Range(x).EntireColumn.Hidden = True)

How to get a container header id to a variable and passed to vba to write a new header?

I have created this script to generate a container that I want to use it to generate containers It works fine but I also need to be able to give the containers a custom header. As you can see I tried to capture the shape id in a variable so I could use the variable to get the shape Id for the container. Nevertheless, I cannot get the shape id or assign one statically I also found out that the container has more than one shape ID. How do I Identify the ID for the header portion. I also need to be able to drop shapes in the container. I followed Microsoft instructions and tried using
vsoContainerShape.ContainerProperties.AddMember vsoShape,
visMemberAddExpandContainer
However that doesn’t work.
Sub Add_Container()
Dim DiagramServices As Integer
DiagramServices = ActiveDocument.DiagramServicesEnabled
ActiveDocument.DiagramServicesEnabled = visServiceVersion140 +
visServiceVersion150
Dim visapp As Visio.Application
Dim vlan30 As Visio.Document
Dim node As Visio.Shape
Dim vlan30id As Integer
Application.Documents.OpenEx(Application.GetBuiltInStencilFile(visBuiltInStencilContainers, visMSUS), visOpenHidden)
Application.Windows.ItemEx("container.vsdm").Activate 'need to activate
Application.ActiveWindow.Page.DropContainer vlan30.Masters.ItemU("Classic"), Nothing
vlan30id = vlan30.ID
Debug.Print vlan30id
Dim v30chars As Visio.Characters
Set v30chars = Application.ActiveWindow.Page.Shapes.ItemFromID(vlan30id).Characters
v30chars.Begin = 0
v30chars.End = 7
v30chars.Text = "Vlan_30"
vlan30.Close
ActiveWindow.DeselectAll
'Restore diagram services
ActiveDocument.DiagramServicesEnabled = DiagramServices
End Sub
I need to be able to get the shape id for the heading of the containers and stored in a variable so I can use the variable for passing the argument in the ItemFromID. Thanks
First things first: your exact question was already answered her: http://visguy.com/vgforum/index.php?topic=6787.0
I packaged the whole code into a function, calling the function will drop a classic container on the page you passed as argument and fill the caption with the passed caption argument. The return value is the dropped Container, bottom function shows how to use the function and add shapes to the container.
'#Folder("ExampleDropContainer")
Option Explicit
Public Function DropContainerWithCaption(pg As Visio.Page, caption As String) As Visio.Shape
Dim vsPg As Visio.Page
Set vsPg = pg
Dim vsStencilName As String
vsStencilName = Application.GetBuiltInStencilFile(visBuiltInStencilContainers, visMSUS)
Dim vsStencil As Visio.Document
Set vsStencil = Application.Documents.OpenEx(vsStencilName, visOpenHidden)
Dim vsMas As Visio.Master
Set vsMas = vsStencil.Masters.ItemU("Classic")
'If you already had the shapes you want to have inside the continer you can replace "Nothing" with them.
Dim droppedContainer As Visio.Shape
'Set droppedContainer = vsPg.DropContainer(vsMas, Nothing)
'Using page.Drop circumvents some issues when a shape already occupies the space where the shape is to be dropped.
Set droppedContainer = vsPg.Drop(vsMas, 0, 0)
droppedContainer.Text = caption
Set DropContainerWithCaption = droppedContainer
End Function
Sub TestExample()
Dim newContainer As Visio.Shape
Set newContainer = DropContainerWithCaption(ActivePage, "Bananas")
'Example on how to add a Shape to the container, someShape is a visio.shape object
'newContainer.ContainerProperties.AddMember someShape
End Sub
You seem to have posted a lot of questions concerning the same or similar problems lately, most of which are quite basic once you get to know VBA. You should read up a bit, especially on the concept of return values of functions. Also be aware that most questions regarding programming in Visio are exactly the same in VBA for Excel, only the interaction with the document/workbook is sometime different. Many answers can be found when searching properly
Some good links are:
How to avoid Select Probably the most read article concerning VBA in Stackoverflow
ExcelMacroMastery Good Resource, a lot on the basics of programming in VBA
Chip Pearson's Website Lots of great and deep information
RubberduckVBA Blog Fantastic resource with many examples on how to bring VBA-Code up to modern standards. He's also active here on SO
The first two links are a must-read IMHO, the other two are great if you want to dive deeper into VBA.

Creating new Section in onenote using VBA

Hi I have searched through the internet looking for examples of creating a new onenote section and I can't find the right example for me to understand. The closest I can get to is using .OpenHierarchy function but I'm still very new to it and I couldn't get the parameters right.
I'm currently working on an OCR marco for multiple PDF file. Everything is working fine till I realise that I'm creating huge waste files on my computer.
Here's the code I used to delete all the pages created in the section
Dim oneNote As OneNote14.Application
Dim secDoc As MSXML2.DOMDocument60
Set secDoc = New MSXML2.DOMDocument60
Dim secNodes As MSXML2.IXMLDOMNodeList
Set secNodes = secDoc.DocumentElement.getElementsByTagName("one:Section")
' Get the first section.
Dim secNode As MSXML2.IXMLDOMNode
Set secNode = secNodes(0)
Dim sectionName As String
sectionName = secNode.Attributes.getNamedItem("name").Text
Dim sectionID As String
sectionID = secNode.Attributes.getNamedItem("ID").Text
oneNote.DeleteHierarchy (sectionID)
oneNote.OpenHierarchy
End Sub
Deletehierarchy function deletes the entire section away leaving no section behind but my OCR macro requires at least one section to work.
Thanks for reading and thank you in advance!
oneNote.OpenHierarchy in vba does not allow bracklet and thats the issue that is causing the error.
solution:
oneNote.OpenHierarchy fileName, "", "New Section 1", 3

Variable not declared before it is used with DAO

I'm using DAO (been asked not to use ADO.NET) to update an Access database. I'm currently thus far, however, VB2008 is telling me that the variable "daoengine" is not declared before it is used. What am I doing wrong in the following code?
Function update_db()
Dim daoengine As DAO.DBEngine
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
dbs = daoengine.OpenDatabase("Project.mdb")
rst = dbs.OpenRecordset("Log", dao.RecordsetTypeEnum.dbOpenDynaset)
End Function
You should have
Dim daoengine As New DAO.DBEngine
instead of
Dim daoengine As DAO.DBEngine
When you say
Dim daoengine As DAO.DBEngine
you're just creating a variable, daoengine, but it doesn't actually point to anything. You need to do this afterwards:
Set daoengine = New DAO.DBEngine
You can also type Dim daoengine As New DAO.DBEngine, but it's better to do it in the two lines above. If you put the New in the Dim line, you create what's called an "auto-instancing" variable which can magically come to life again after you thought you'd disposed of it.
For more details see the Don't Use Auto-Instancing Object Variables here: Declaring Variables (in VBA)

How to do Mailmerge in Openoffice using Vb.net

Its 5th Question and apart of one I didn't get response from the experts....
Hope this time I will get the helping hand.
I want to do mailmerge in openoffice using Vb.net and I am totally new with openoffice.
I searched on net for some help to understand how to use openoffice with vb.net but all I get is half info.....So can you please help me and give me code for mailmerge in vb.net for openoffice.
Well i have list of workers in DB and there is this facility that if they want to mail to all or some of the workers then they can do it.I have completed this task using Microsoft Office now as a Add in we are providing the facility to perform the same task using Open Office.
What they have to do is just select the List of workers and click on a button and it will automate the mailmerge using the field of those workers data from DB. The Code of mine is as shown below
Public Sub OpenOfficeMail(ByVal StrFilter As String)
Dim oSM ''Root object for accessing OpenOffice from VB
Dim oDesk, oDoc As Object ''First objects from the API
Dim arg(-1) ''Ignore it for the moment !
''Instanciate OOo : this line is mandatory with VB for OOo API
oSM = CreateObject("com.sun.star.ServiceManager")
''Create the first and most important service
oDesk = oSM.createInstance("com.sun.star.frame.Desktop")
''Create a new doc
oDoc = oDesk.loadComponentFromURL("private:factory/swriter", "_blank", 0, arg)
''Close the doc
oDoc.Close(True)
oDoc = Nothing
''Open an existing doc (pay attention to the syntax for first argument)
oDoc = oDesk.loadComponentFromURL("file:///C:\Users\Savan\Documents\1.odt", "_blank", 0, arg)
Dim t_OOo As Type
t_OOo = Type.GetTypeFromProgID("com.sun.star.ServiceManager")
Dim objServiceManager As New Object
objServiceManager = System.Activator.CreateInstance(t_OOo)
Dim oMailMerge As New Object
oMailMerge = t_OOo.InvokeMember("createInstance", Reflection.BindingFlags.InvokeMethod, Nothing, _
objServiceManager, New [Object]() {"com.sun.star.text.MailMerge"}) 'com.sun.star.text.MailMerge"})
oMailMerge.DocumentURL = "file:///C:\Users\Savan\Documents\1.odt"
oMailMerge.DataSourceName = CreateSource(StrFilter)''Function that will return the datasource name which will be a text file's path
oMailMerge.CommandType = 0
oMailMerge.Command = "file:///C:\Mail.txt"
oMailMerge.OutputType = 2
oMailMerge.execute(New [Object]() {})**---->I am getting Error here**
End Sub