Following vb.net code checks if ARS folder exists in Outlook.
Following code works very well.
But I need a better code.
Better code means without using On error goto statement.
VBA does not have structured exception handling (try/catch in C++, C#, VB.Net or try/except in Delphi). Since MAPIFolder.Folders.Item raises an exception if the specified folder is not found, VBA can only handle exceptions using "on error goto".
In VBA.Net, try something like the following (off the top of my head):
Try
myNewFolder = myFolder.Folders("ARS")
Catch
myNewFolder = myFolder.Folders.Add("ARS")
End Try
Related
I have some code in VC++ that create windows explorer shell integration and shows some remote database folders in windows explorer as native folders. When I use "move to folder..." from the explorer menu and move some file to that virtual folder, windows give me error message "The target can't handle this type of document", even though the shell integration successfully moves the file to the database.
I am not able to find out what is the cause of that error and how to disable the same from my code, what configuration is needed.
Does anyone has an idea about the same.
I finally figured it out, Drop was returning hr instead of S_OK. the hr value came from some other method call and was wrongly returned as something else instead of S_OK.
It just in one of the if condition, the original developer has forgotten to set the hr value correctly. normally hr values are not used, it just for storing the result of a method call and returning the same at the end, so its very hard to figure what is wrong, because all methods are working properly.
These silly mistakes are hard to find, though easy to fix.
Thanks Denis for pointing where to look.
I have used one error handler code in my all vb6 projects,
Now I have to remove that error handler code which is in all sub procedures, functions.
I have to remove it manually all the time can it be removed automatically
I approached a task similar to this one time by writing a small program that would
1) read the project's vbp file and retrieve the names of all the files in a project
and
2) would then edit each of these files and make the desired changes.
As the title says, I've got a word template with macros that does not run properly in the new Word version from Office 2011 for MAC.
The thing which seems to not work properly is the following code:
Sub Document_New()
myForm.Show
End Sub
The same is with Document_Open()
It doesn't seem to run this code on the Mac version.
Does anyone know why this won't work on the Mac, or if there's another way around to emulate the document_open/document_new function?
EDIT: The document is in the .dot format. And I tried to save it to .doc, then the Document_open() worked just fine, so it seems to not be working in the .dot format.. And Document_New() is not running in .doc since its not a new templatefile based on a document..
EDIT 2: Seems like it was a once only with the Document_open on .doc files. I cant make it work again. So weird! The only event I get working, and this is only when using the .doc file format, is Document_Close() - this works everytime...
EDIT 3: This is just getting weirder. I made a new .doc document with the following code:
Private Sub Document_Open()
MsgBox ("BlaBlaBla")
End Sub
The code only runs if the Visual Basic Editor is open BEFORE I close the word file and try to open it again. If I close the Visual Basic Editor and then the word file, and then open the word file; The code is not run.
??
All VB application events are suppressed if you have the VB-editor active, and the current project is not running. It is an intentional behavior, to prevent unwanted code execution, hence not debuggable.
I have used Workbook_Open() (in Excel), and I can only see it working on newly open Excel Xls (xlsm on 2010), from a non-open VB-editor Excel application.
It will work if you have other doc/xls already open, but not if vb-editor is up.
Have you checked whether Macros are allowed? Do you have generated a certificate and setup your application as a trusted source?
I'm having similar issues. It seems that MS removed support for the Document_New and Document_Open functions in the Word object model for Word 2011. See http://mac2.microsoft.com/vb/1033/Word/html/womscChangesBetweenWord2010and2011.htm
I created a skeleton Active X DLL with its Instancing property set to MultiUse and only one function which does nothing but pop up a message box saying that it has been called.
Then I created a test program and added the DLL to its References.
I added code to declare a variable of the DLL's Classmodule, to create a new object and to call the function.
In all cases I used Intellisense code completion, so VB6 certainly about the DLL and it's class & method.
However, when I run the tester it reports runtime "error 91 object variable or With block variable not set" when trying to create the New object.
This is new territory for me, so hopefully it is something obvious.
Update: I added a message box in a DLL fn() to say that it had been called, then went to a real life web site that uses Active X to call into the DLL and saw the message box - but I still get the error in a VB tester application(!?)
It would be easier to find the problem if you could post the calling code and the DLL class.
Here's a guess. Have you remembered the Set on the line that creates the new object?
Correct code
Set obj = New MyDLL.MyObject
Incorrect code
obj = New MyDLL.MyObject
Try changing the function in your active x dll to return a message instead. Show your message box in your calling code, not in the dll.
Else, try in command prompt, regsvr32 "myDll.dll", and then run your code.
Is there a possibility to deactivate / activate all try catch blocks in the whole project as easy as clicking a button?
I need this for debugging when I don't want the catch block to handle the exception, but instead prefer that VS breaks into the code as if the try catch block was not there.
At the moment I am commenting out the try/catch blocks but this is inefficient.
Environment: VS 2008 with C# as language.
To catch exceptions the moment they're thrown ("first-chance exceptions" in Win32 parlance):
in VS2008: go to Debug, Exceptions...
by VS2015: this has been moved to Debug > Windows > Exception Settings
Then check the box Thrown for Common Language Runtime Exceptions.
There is no way to deactivate try/catch blocks.
However, for debug purposes, if you want to break as soon as a particular type of exception is thrown, you can get Visual Studio to do that (Debug -> Exceptions; select the exception type you're interested in and check the "Thrown" box).
Thought about this today and found an other solution. The advantage of this is that the IDE will stop at the exact point of the occuring exception.
Somewhere globaly defined:
Namespace Global.System
Public Class NeverOccurException
Inherits Exception
End Class
End Namespace
At the beginning of each source code file:
#If DEBUG
Imports CatchAtReleaseException = System.NeverOccurException
#Else
Imports CatchAtReleaseException = System.Exception
#End If
Usage:
'Compiled in DEBUG-Mode the TryCatch is "disabled", because the
'the ALIAS CatchAtReleaseException is set to "NeverOccurException"
'Compiled as RELEASE the TryCatch is "enabled", because the ALIAS
'is set to the regular "System.Exception"
Public Sub SampleSub()
Try
'...
Catch ex As CatchAtReleaseException
End Try
End Sub
Have fun with it,
Greetings,
Ted
If you want to do in the IDE, Debug -> Exceptions is the dialog where you can ask the IDE to break when a specific/category/all exceptions are thrown.
You can change the way Visual Studio breaks when an exception occurs. By default, it breaks on unhandled exceptions. If you go to menu Debug > Exceptions, you can uncheck Common Language Runtime Exceptions and make other changes in the IDE's behavior when exceptions occur. For example, you can have it break on only one kind of exception; there's a long list there.
I have done this on rare occasions when trying to debug.