|
Sure, thanks
|
|
|
|
|
Hello everybody,
I could youse some help with VBA.
The case is: I have a folder with lots of Outlook .msg files and I need to extract their metadata like Subject, Sender and Send date to an Excel spreadsheet.
I am new in VBA and I would be very grateful for any advice you could give me! Thank you!
With Best Regards
Alex
|
|
|
|
|
I found this code:
Sub GetMailInfo()
Dim MyOutlook As Outlook.Application
Dim msg As Outlook.MailItem
Dim x As NameSpace
Dim Path As String
Dim i As Long
Set MyOutlook = New Outlook.Application
Set x = MyOutlook.GetNamespace("MAPI")
Path = "C:\Users\Alexander.Scott-Zhuk\Desktop\Messages\"
FileList = GetFileList(Path + "*.msg")
Row = 1
While Row <= UBound(FileList)
Set msg = x.OpenSharedItem(Path + FileList(Row))
Cells(Row + 1, 1) = msg.Subject
Cells(Row + 1, 2) = msg.SenderName
Cells(Row + 1, 3) = msg.SenderEmailAddress
Cells(Row + 1, 4) = msg.CC
Cells(Row + 1, 5) = msg.To
Cells(Row + 1, 6) = msg.SentOn
Cells(Row + 1, 7) = msg.Size
If msg.Attachments.Count > 0 Then
For i = 1 To msg.Attachments.Count
Cells(Row + 1, 7 + i) = msg.Attachments.Item(i).FileName
Next i
End If
Row = Row + 1
Wend
End Sub
Function GetFileList(FileSpec As String) As Variant
Dim FileArray() As Variant
Dim FileCount As Integer
Dim FileName As String
On Error GoTo NoFilesFound
FileCount = 0
FileName = Dir(FileSpec)
If FileName = "" Then GoTo NoFilesFound
Do While FileName <> ""
FileCount = FileCount + 1
ReDim Preserve FileArray(1 To FileCount)
FileArray(FileCount) = FileName
FileName = Dir()
Loop
GetFileList = FileArray
Exit Function
NoFilesFound:
GetFileList = False
End Function
But it doesn't work for me. When I run the macro I receive a runtime error message:
"runtime error 1004 method 'cells' of object '_global' failed"
and when I click debug it highlights this line:
Cells(Row + 1, 1) = msg.Subject
Do you have any clue, what am I doing wrong? Please help!
|
|
|
|
|
Are you running this from within an open Excel workbook?
|
|
|
|
|
Hello Richard,
no, I actually was running the macro from Outlook-VBA, but thank you for pointing me on that. I copied the code into the Excel-VBA and it worked perfectly! Thank you a lot!
But I still have the question, how do I make it work from Outlook and save it into Excel-File?
Alexander
|
|
|
|
|
At the beginning of the macro you have some code like:
Dim MyOutlook As Outlook.Application
Dim msg As Outlook.MailItem
Dim x As NameSpace
which starts the Outlook application and sets some references. If you want to run it from Outlook then you need some similar code that loads the Excel application and creates a new workbook. I do not know the exact code but take a look at Application Object (Excel)[^].
|
|
|
|
|
Ok thanks for your advise, I will look at this article closer.
|
|
|
|
|
Good day friends! Please, am currently working on a game and am having a challenge. I want enemies to appear smaller when far from the player and bigger when closer. Any solution is welcome please.
|
|
|
|
|
Since we know NOTHING AT ALL about your game, it's implementation, raster or vector graphics, ..., it's pretty much impossible for anyone to tell you anything useful.
Well...other than Google for "scaling 2d raster graphics" or something similar depending on your implementation.
|
|
|
|
|
Hello and thnx in advance for the help.
I have to send a packet of data, to the network broadcast, using UDP, to get the members of this particular intranet to respond (they are all PLCs).
I know the hex format of the message, say:
""43:44:50:00:01:00:00:00:00:00:00:00:00:ff:00:00:00:00:00:00:00:03:00:06:00:00:00:28:c0:a8:fc:fa:00"
colons are byte separators.
How do I pack it into the command MSG?
Dim myIP as IPAddress = "some.ip.addr.255"
Dim myPort as Integer = someport
private const myCmd as string = "43:44:50:00:01:00:00:00:00:00:00:00:00:ff:00:00:00:00:00:00:00:03:00:06:00:00:00:28:c0:a8:fc:fa:00"
dim HexSplit() as string = split(myCmd, ":")
dim byteCMD as byte() = new byte()
dim lCounter as integer
for each hS in HexSplit
byteCmd(lcounter) = CByte(Val("&H" + hS))
lcounter += 1
next
udpClient.Connect(myIP, myPort)
mRet = udpClient.Send(byteCmd, byteCmd.length)
|
|
|
|
|
I don't know, what you try to achieve and where your issue is ...
What does the Byte-Values from your Command-String mean ?
Which PLC's do you try to connect by this way ?
What kind of respond do you await ?
What should happen then ?
|
|
|
|
|
|
Hi Richard.
Interesting way to connect me.
I followed your link and posted a solution to this.
Thank you ...
|
|
|
|
|
|
Hi everyone.
I'm going to go directly to the question.
I am trying to create an app that creates a barcode and it's going to be copied to a PDF file, but that's not the problem:
I've all the code to create the barcode (the type is EAN-13) but the only thing that's missing is the size of it. By default, the size of the barcode generated with iTextSharp is really small. I have it in a PictureBox and I can change only the height of it, I need also the width and if it's possible, without losing quality.
Practically I obtain all the code from here: [^] . You can download the project if you want at the botton of that page.
So, finally, as I said, the question is that if there's any method to change the width or size (make it bigger) of the barcode without losing quality.
I think I don't forget nothing.
Thank you all in advance!
Bye.
modified 27-Jun-16 16:05pm.
|
|
|
|
|
Any assistance is appreciated,the code below just does not seem to update the textbox when button 1 is clicked. The script is split from a larger application just to give to highlight the issue.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim a As New doSomething
Dim s As New Threading.Thread(AddressOf a.update)
s.IsBackground = True
s.Start()
End Sub
End Class
Public Class doSomething
Public Sub update()
SetControlText(Form1.TextBox1, "Hey Please Update the Textbox")
End Sub
Private Delegate Sub SetControlTextInvoker(ByVal ctl As Control, ByVal text As String)
Private Sub SetControlText(ByVal ctl As Control, ByVal text As String)
If ctl.InvokeRequired Then
ctl.Invoke(New SetControlTextInvoker(AddressOf SetControlText), _
ctl, _
text)
Else
ctl.Text = text
End If
End Sub
End Class
|
|
|
|
|
Try passing the real instance of Form1 to the doSomething class, rather than relying on the auto-created instance that only exists for VB6 compatibility.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim a As New doSomething
a.Target = Me.TextBox1
Dim s As New Threading.Thread(AddressOf a.update)
s.IsBackground = True
s.Start()
End Sub
End Class
Public Class doSomething
Public Property Target As TextBox
Public Sub update()
SetControlText(Target, "Hey Please Update the Textbox")
End Sub
Private Shared Sub SetControlText(ByVal ctl As TextBox, ByVal text As String)
If ctl.InvokeRequired Then
ctl.Invoke(New Action(Of TextBox, String)(AddressOf SetControlText), ctl, text)
Else
ctl.Text = text
End If
End Sub
End Class
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
i am trying to add records to database by Lynx grid, but i did not understand perfect code.
i googled also, but not find right example
Can any one give me best example
|
|
|
|
|
i am trying to add records to database by Lynx grid, but i did not understand perfect code.
i googled also, but not find right example
Can any one give me best example
|
|
|
|
|
I previously used Word for Mac 2011 where I recorded the following macro to set all margins at 0.4". I tried recording the same macro on Word for Mac 2016 but the keystrokes were not recorded. I tried to copy and paste the following code into the Word for Mac 2016 VB editor, but I got a compiler error. Can you help me debug it? Thanks.
Sub Macro1()
'
' With ActiveDocument.PageSetup
.LineNumbering.Active = False
.TopMargin = InchesToPoints(0.4)
.BottomMargin = InchesToPoints(0.4)
.LeftMargin = InchesToPoints(0.4)
.RightMargin = InchesToPoints(0.4)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0.5)
.FooterDistance = InchesToPoints(0.5)
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
End With
End Sub
|
|
|
|
|
Member 12603473 wrote: but I got a compiler error. Unfortunately we cannot see your screen, so have no idea what error that may be.
|
|
|
|
|
I copy-pasted it below. I also have screenshots but I don't see how to upload them to you. I apologize for being new to this forum.
Sub Macro1()
'
' With ActiveDocument.PageSetup
.LineNumbering.Active = False
.TopMargin = InchesToPoints(0.4)
.BottomMargin = InchesToPoints(0.4)
.LeftMargin = InchesToPoints(0.4)
.RightMargin = InchesToPoints(0.4)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0.5)
.FooterDistance = InchesToPoints(0.5)
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
End With
End Sub
|
|
|
|
|
That is exactly what you posted in your original question. But you still have not told us what the error is.
|
|
|
|
|
When I run the macro, a small window pops up that says "Compile error: Invalid or unqualified reference". When I click "OK" the code comes up and ".LineNumbering.Active =" is highlighted. If I delete the entire ".LineNumbering.Active = False" line and try again, I get the same compiler error message and now ".TopMargin =" is highlighted.
I am no expert on VBA by any stretch of the imagination, but it seems to me that the reference "ActiveDocument.PageSetup.anything" is invalid. As soon as the complier tries to reference ActiveDocument.PageSetup.whatever, it spits out the Compile error.
Since exactly this code worked fine in Word for Mac 2011, was there some change in reference syntax in Word for Mac 2016 that I don't know about? I also found it curious that I could record certain keystrokes with "Record Macro" in Word for Mac 2016 but not certain drop-down menu commands. I hope that this is not a bug in Word for Mac 2016.
Thanks for your patience.
|
|
|
|
|
I just noticed the following in your code snippet:
Sub Macro1()
.LineNumbering.Active = False
The first line of your macro is commented out, so you do not have a reference for all the following lines.
|
|
|
|