Lotus script to move mass domino users mail databases from csv file - lotus-notes

I need a lotus script for mass move of users mail files from one domino directory to another. I've found script for mass user deletion and just replaced method notesAdministrationProcess.DeleteUser with method noteID$ = notesAdministrationProcess .MoveMailUser( username$ , newhomeserver$ , newhomeservermailpath$ ) , where is newhomeservermailpath$ - moved - directory which I previously created to move mail files from default mail folder mail. Domino console didn't report any error but script doesn't move user's mail files. What is missing? Am I doing something wrong?
Script code:
Sub Initialize
Dim session As New NotesSession
Dim db,addbk As NotesDatabase
Dim usrvw As NotesView
Dim Username As String
Dim movecounter As Integer
Dim nap As NotesAdministrationProcess
Dim FIleNumber As Integer
Dim Filename As String
Set nap = session.CreateAdministrationProcess("MyServer/myserverdomain")
Set db = session.CurrentDatabase
Set addbk=session.GetDatabase("MyServer/myserverdomain","names.nsf",0)
Set usrvw=addbk.getview("$NamesFieldLookup")
filenumber%=FreeFile()
fileName$="D:\moveMail.csv"
Open fileName For Input As fileNumber%
On Error Resume Next
movecounter=0
Do Until EOF(fileNumber%)
Input #fileNumber%,Username
movecounter=movecounter+1
Call nap.MoveMailUser(Username, MyServer/myserverdomain , moved)
Print "Moved" & CStr(movecounter) "Users"
Loop
End Sub

There are -as stated in comments- some major problems with your code:
First: NEVER use "On Error Resume Next" except for expected single errors you want to suppress.
Your case is the best example: Your code fails because of non defined variables, but you will never get an error message because you suppress it: No chance of knowing where it went wrong.
Second: EVER add
Option Declare
to any code you write in LotusScript. There is even a Designer setting to do this automatically. This option would have checked if all variables you use are declared... and would have not even allowed you to save this code.
Third: The errors in code. You managed to produce 2 errors when changing one single line of code...
This is how it looks:
Call nap.MoveMailUser(Username, MyServer/myserverdomain , moved)
This is how it should look:
Call nap.MoveMailUser(Username, "MyServer/myserverdomain" , "moved")
Just look at the difference... I will not start to teach you basics about variables vs. string literals as these are the same for almost every programming language.
-off topic-
One more thing: The way you approach business tasks is reckless at least but in any case very dangerous... You seem to copy some code from somewhere but even lack the very basics in coding. Seeing that you delete productive users and move productive mail databases I would be very concerned when I saw you doing this via "trial and error"... But this is just my point of view...
-/end off topic-

If you do it in the Administrator client, moving a user's mailfile consist of several steps, see https://help.hcltechsw.com/domino/10.0.1/admn_moveamailfilefromoneservertoanother_r.html
Check mail server's access
Create new mail file replica
Add new mail file fields
Monitor new mail file fields
Replace mail file fields
(user has to login to Notes client, or you have to create AdminRequest programmatically)
Push changes to new mail server
Get mail file information for deletion
Approve mail file deletion

Related

Referencing an ExcelApp Object That Is Running in a Different Process (by A Different User) in VB6

So I have this problem with my app. It is supposed to take user inputs and archive them in Excel files. All of that would work just fine, if I didn't need to access said Excel files as a special user due to the company's safety restrictions.
I have a working piece of code that opens said restricted files just fine through creating a new process (it is pretty much the same as the one here).
I use the code as such:
Sub RunAsUser_Main()
Dim ExeCommand As String
ExeCommand = "C:\Program Files\Microsoft Office\Office16\EXCEL.EXE \\192.168.88.3\share\public\Workbook.xlsm"
RunAsUser "username", "password", "domain", ExeCommand, "C:\Windows"
'-------------------- OPEN WORKBOOK --------------------
Dim ret As Integer
Dim ExcelApp As Object
Dim WorkbookPath As String
Dim MyWorkbook As Object
On Error Resume Next
Set ExcelApp = GetObject("Excel.Application").Application
If ExcelApp Is Nothing Then
ret = MsgBox("error!", vbCritical + vbOKOnly, title)
Exit Sub
End If
...
All goes good right until the GetObject statement. The new process starts, Excel opens the workbook as it should and I have verified that it is run by the special user.
After this though, I am unable to reference the running ExcelApp object. It just returns nothing.
What is wrong with this code? I have very little experience with creation and management of processes, so I might be failing to see the obvious.
Thanks in advance!
Edit: After some more trying, I believe that there is no way to reference the workbook using standard commands (GetObject etc.). I will need some special code to make this work, and have no idea for where to look for it. Any advice on this?
I've also used the code from this thread that is supposed to list all current instances of excel. It does list the ones running under my current user, but does't register the one under my special user, same as with my previous attempts.

Word gets stuck during export via Excel VBA

My Excel VBA script contains an export function which results in one Word document of about 12 pages.
On my private computer, this works.
On my company's laptop this seems to take too long and probably some kind of Word watchdog is triggered. Word gets stuck after about 75% of the code and the message "Word has stopped working" pops up.
I determined the point where it gets too much for Word to handle. As the export code is quite extensive and also contains several company and project details that I don't want to reveal, I prefer to not post it here.
Here is the snippet at which Word gets stuck:
ThisWorkbook.Worksheets("Backup - Do not change").Shapes("companyLogo").Copy
With wdFrontHeaderTable
.rows.Height=30
With .Cell(1,1).Range
.Paste
.ParagraphFormat.Alignment=0
End With
With .Cell(1,1).Range.InlineShapes(.Cell(1,1).Range.InlineShapes.Count)
.LockAspectRatio=msoTrue
.Width=120 'this one still works
End With 'here, the error occurs
End With
If I set one before that point and then run the two halves of code, one after another, it works.
If I uncomment the whole block, the error occurs in the next block.
The code does what it is supposed to do, even on the company laptop. I guess it just takes too long and the watchdog "thinks" Word was stuck.
Is there a way to disable the watchdog or another way to solve this?
I tried Application.Wait (1000).
Word is initialized by
Dim wdApp As Object
Dim wdDoc As Object
Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.Documents.Add

How can I have an Excel VBA application in use without multiuser lock?

I have an app I coded in Excel that suits the needs of my project; it serves the purpose of keeping track of quite a lengthy process and prerequisites and such.
It feeds off of a certain number of tables in my file.
The thing is, only one user can currently work on that file; and since we have multiple teams working on different parts in parallel, it would be nice to host that somehow in a way that would remove the single-user restriction.
Do any of you have an idea of how I could work around this?
I worked on a solution for a very similar project of keeping track of a hospital's labor utilization (nursing employee census, if you will) on a day-to-day basis across every nursing-based department in the hospital system. This solution relies on a couple conditions:
That it will be unlikely two or more people will need to save data to the final file at the same time (meaning within seconds of each other).
All the various users of the file will have access to at least one commonly-shared network drive or location.
In our case, we created a new file each day, but it wouldn't be difficult to adjust the data-writing code to append data, rather than create a new file and dump data into that new file.
The rough outline of the process is this:
Create a read-only destination file (.xlsx in our case) in a network location that contains tables of data split between n worksheets.
Create an interactive form (.xlsm) that allows user input and then on form submission, opens the destination .xlsx file and saves the form data to it, then closes it. This interactive .xlsm file can be placed in the same network location, with shortcuts created on as many peoples' desktops (or departmental shares, for example) as necessary.
With the speed of Excel and VBA, this means you're only "opening" the destination file for a second or two to write the form data, no matter how long one user may have a copy of the form open.
One thing that will be necessary is to check if the file is open, and gracefully alert the user if they need to try again, which you can do with a function covering the related error codes, for example:
Function IsFileOpen(FileName As String)
Dim iFilenum As Long
Dim iError As Long
On Error Resume Next
iFilenum = FreeFile()
Open FileName For Input Lock Read As #iFilenum
Close iFilenum
iError = Err
On Error GoTo 0
Select Case iError
Case 0: IsFileOpen = False
Case 70: IsFileOpen = True
Case 53: IsFileOpen = "Not Found"
Case Else: Error iError
End Select
End Function
which can be called via some code like (pseudo code):
Private Sub UpdateData(ByVal thesheet As String)
Dim xlApp As New Excel.Application
Dim xlWkbk As New Excel.Workbook
If Not IsFileOpen(FileName) Then
Set xlWkbk = xlApp.Workbooks.Open(filename)
xlWkbk.Worksheets(theSheet).Activate
Else
MsgBox "Sorry, the file is currently in use. Please try again", vbOKOnly
Exit Sub
End If
End Sub
Or you could have it simply wait a few seconds (e.g. Wait 5) or more if the writing process doesn't cover that much data. The specific amount of seconds to wait would depend on testing write times based on your scenario and your data. That would be added as a nested If Not statement inside the previous one.
Then, when the result is that the file is not in use, simply write a series of subroutines to write the form data (stored as variables) to the destination sheet. End with something like
xlWkbk.Save
xlWkbk.Close
Set xlWkbk = Nothing
Set xlApp = Nothing
to save and close the workbook and clear your variables (memory cleanup and all that).
You may already be aware of this practice, but while you'll want to keep Excel visible during development, you'll definitely want to set Application.Visible = False on the production files for two reasons:
This will prevent users from getting confused by a lot of automation
It covers Application.Updating as well, which will really speed up data processing.

Unable to find the right excel file library reference error

Every time I open this Excel file I get this error which is in screenshot 1 and screenshot 2.
When I click OK it takes me to code windows and asks me to select library.
I tried everything to make it work but no luck.
Screenshot one and screenshot two:
Make sure that these references are in this Priority order.
HTML and Internet Controls need to be above OLE Automation.
If you are still having this issue after this, run a Repair on the Office install and it refreshes the .DLL files that may have been corrupted.
Update: 7/6/2017
The pervious answer above will re-associate the references and allow the script to compile.
However, there is a better way.
This issue occurs when the VBA script is shared to other computers that are not identical platforms(OS and MS Office versions) and use early binding. Early binding reduces latency and is the correct way when only intended for one computer.
The answer is to use late binding format in the script and not select any references. Change any data type objects other than object back to object and use the following format:
Sub Late_Binding()
Dim IE_App_obj As Object
Dim MyShell_obj As Object
Dim IE_Window_obj As Object
Dim Windows_cnt As Long
Dim x_cnt As Variant
Dim HTML_Element_obj As Object
Set IE_App_obj = CreateObject("InternetExplorer.Application")
'Use IE_App_obj to Navigate to webpage and control it.'
Set MyShell_obj = CreateObject("Shell.Application")
'Use MyShell_obj to find an existing webpage and control it.'
Let Windows_cnt = MyShell.Windows.Count
For x_cnt = Windows_cnt - 1 To 0 Step -1
On Error Resume Next
If Instr(MyShell_obj.Windows(x_cnt).Document.Title,"WebPage_Title") > 0 Then
Set IE_Window_obj = MyShell_obj.Windows(x_cnt)
Exit For
End If
Next
Set HTML_Element_obj = IE_Window_obj.Document.getElementByID("ID_text")
End Sub
Latency will increase but so will stability.

notes url (notes://) sometimes does not create icon on workspace

I'm maintaining an application which sends out E-Mails with a notes url link like this:
noteshref = "notes://" & serverName.Common & "/" & docToLink.Parentdatabase.Replicaid & "/" & viewUNID & "/" & docToLink.Universalid
the viewUNID is calculated thusly:
Dim viewUNID As String
Set nc = db.Createnotecollection(False)
nc.Selectviews=True
nc.Selectionformula={#isMember("Vtousdocuments";#explode($Title;"|"))}
nc.Buildcollection
If nc.Count > 0 Then
viewID = nc.Getfirstnoteid
Dim note As NotesDocument
Set note = db.Getdocumentbyid(viewID)
viewUNID=note.Universalid
Delete note
Else
viewUNID="0"
End If
Delete nc
I've looked at the documentation for the NotesURL:
https://www-10.lotus.com/ldd/dominowiki.nsf/dx/notes-urls
I've seen demonstrations via a remote session when the database icon on the workspace is not created when opening the link. The Document gets opened, but no bananas on the 'create a Workspace icon on the database' behaviour.
I haven't been able to reproduce this on my machine, and I've also noted that, contrary to the documentation, the server 'hint' is not considered - one of the possible replicas is pulled out of thin air and recreated on the workspace.
Am I missing anything? Are there perhaps some combinations of the notesurl that do not create icons on the workspace (i.e. a naming convention for the server)? Or could it be something more obscure, like corrupted desktop.ndks?
I have used this URL format in few places and it has always worked and it opens the right server. One thing I do differently is use /0/ instead of the view UNID "/" & viewUNID & "/". This would directly open the document if its present in the db and its also faster.
But your solution also should work, if the issue is specific for few users you should delete the cache/desktop and try.

Resources