Quantcast
Channel: VBForums - Office Development
Viewing all 4673 articles
Browse latest View live

I need help - Macro to print page to pdf and send to a person on a list

$
0
0
Hi peeps

I have a 70+ paged worksheet that I would manually print to pdf attach to an email and send out.

Is there a macro that can send a specific page of a worksheet to a specified email with specific subject line and email body based on a table?

Page Email Address CC Subject Email Body
1 Test1@Test.co.nz Test1@Test.co.nz Invoice attached Hi John, please see test
2 Test1@Test.co.nz Test1@Test.co.nz Invoice attached Hi John, please see test
3 Test1@Test.co.nz Test1@Test.co.nz Invoice attached Hi John, please see test
4 Test1@Test.co.nz Test1@Test.co.nz Invoice attached Hi John, please see test
5 Test1@Test.co.nz Test1@Test.co.nz Invoice attached Hi John, please see test


I have been able to do a bit of code to convert an excel sheet to a pdf and send it via gmail but I dont know what the next steps are

Any feedback would be greatly appreciated.

Cheers

[RESOLVED] Run Time Error 1004 application defined object defined

$
0
0
I am using the following code to only display dates between a start date and end date

Code:

Public Sub MyFilter()
    Dim lngStart As Long, lngEnd As Long
    lngStart = Range("Hidden!O31").Value 'assume this is the start date
    lngEnd = Range("Hidden!O32").Value 'assume this is the end date
    Range("I15:ARR15").AutoFilter field:=1, _
        Criteria1:=">=" & lngStart, _
        Operator:=xlAnd, _
        Criteria2:="<=" & lngEnd
End Sub

Bu I am coming up with an error Run Time Error 1004 application defined object defined error, I think it may be because I am taking the start date and end date from another sheet but that would be just a guess any ideas

[RESOLVED] Need help writing some VB code

$
0
0
Hi, this is my first post so I don't know how it works yet.

If someone could write/assist me on some code that would be great, I'm looking for the code to:

Search a word document looking for "_id#" (the # is any number) and if it duplicates anywhere in the document to chance them both to "_id#(partial)".

Any help would be great as I am stumped...

Thanks

Adam, (a.k.a YodaBadger)

MsOf365 Macro / VB Coding help needed again please

$
0
0
Good day,

Could someone help me again with the below.

I have a workbook containing 9 sheets.

Sheet 1 has dropdowns which in turn autofill's the other sheets. I have added checkboxes below which I would like to select which sheets needs to be printed and saved as pdf (PDF sheets would need to be merged as one and link to a reference on sheet 1)

eg. if sheet 2,3,4,5,6 is selected these would need to print and save as pdf (note i would need to state how many copies to print as some requires 1 copy and others require 3 copies of each of the selected sheets)

The below code can be manipulated to get the result as it prints and saves 100% (Thanks to Siddharth) but to link this to 9 different checkboxes and to merge the sheets to 1 pdf stumps me completely.

Thank you in advance.

Sub sample()
Dim wb As Workbook
Dim wsI As Worksheet
Dim NewFileName As String

Set wb = ThisWorkbook

Set wsI = wb.Sheets("Packing List")

With wsI
NewFileName = "C:\Users\JJ\Desktop\Exports\" & .Range("Input","B7").Value & ".pdf"

.Range("A1:N31").ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=NewFileName, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True

End With

MsgBox ("PDF Saved and Generated")

ActiveSheet.PrintOut

End Sub

MsOf07 Save as PDF with default folder and default name

$
0
0
Hi

I am trying to create a VBA code that will save my excel sheet in a pdf format. The difficult part is that I will want a default folder from which I can choose another folder to save the file. Furhtermore, I want the filename to start with Report....

You can see my code here: The VBA code fails in the red-area.

Sub ActiveSheet()
'www.contextures.com
'for Excel 2010 and later
Dim wsA As Worksheet
Dim wbA As Workbook
Dim strTime As String
Dim strName As String
Dim strPath As String
Dim strFile As String
Dim strPathFile As String
Dim myFile As Variant


Set wbA = ActiveWorkbook
strTime = Format(Now(), "yyyymmdd\_hhmm")

'get active workbook folder, if saved
strPath = "\\personalfolder\"

'replace spaces and periods in sheet name

strName = Replace(strName, ".", "_")

'create default name for savng file
strFile = "Report" & "_" & strTime & ".pdf"
strPathFile = strPath & strFile

'use can enter name and
' select folder for file
myFile = Application.GetSaveAsFilename _
(InitialFileName:=strPathFile, _
FileFilter:="PDF Files(*.pdf), *.pdf", _
Title:="Select Folder and FileName to save")
'export to PDF if a folder was selected
wsA.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=myFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False

'confirmation message with file info
MsgBox "PDF file has been created: " _
& vbCrLf _
& myFile
End If

exitHandler:
Exit Sub
errHandler:
MsgBox "Could not create PDF file"
Resume exitHandler

End Sub

need a code to remove special character

$
0
0
hi -

I badly need your help to provide me a code to remove special character and replace it with the space. All I need to replace are column A, B, C, D. Also, need also help to convert the column E, G, H and Z to custom mm/dd/yyyy.

Would appreciate a big help if you can help me on this.

Thanks!

MsOf10 [Excel 2010] Select Row in ListBox1 and entry other data in ListBox2

$
0
0
Hello Community,

i'm new here since today and i'm from germany. It's hard for me to explain my Problem because my english is not so well and the goolge translator a piece of garbage.

Okay now i start with my main Problem:

I wann click in ListBox1, okay done thats not so hard for me. then in this ListBox1 are 5 Columns.
I wanna split those 5 columns in 5 own values and search for in the Worksheet1. okay now i get my data and wanna post this in ListBox2.

example:
ListBox1 (City, CourseName, ModuleNr, trainer, max. participants)
(Musterhausen | Course 1 | Module 6 | Mrs. Müller | 23)

ListBox2 (Name, First name, BirthDay, CustomerNr.)
(Müller, Max, 01.01.1901, 123456789)

But this person should only import to ListBox 2 if all data match.
I have no idea :(

I hope somebody can help me. :)

Sincerely
ExploShot

(Excel) Macro, uses timer to only allow data entry from barcode scanner?

$
0
0
Hello,

I am attempting to create a macro that uses a keypress or keydown event to block any data entry that takes longer than 1 second to insert. I want the macro to measure the amount of time from the first keystroke made after focusing on a cell, to the press of the ENTER or TAB buttons. The macro should clear any data entered into the focused cell if the time taken to enter the data is greater than 1 second. This should prevent anyone from manually entering in data into a cell via the keyboard and only allow data entered in via a barcode scanner. I have perused the internet and found plenty of people talking about macros that do this but have yet to find a working example.


-Trace

Writing problems to a Range

$
0
0
Hi,

I'm using range to select a specific column in a specific worksheet for the information contained
in each cell along the column. I can read the individual values but I'm not able to write a new value into
particular cells. I'm stumped at this point...probably overlooking something obvious....

Code:


        Dim rng As Variant
        Dim x    As Long

                (previous code to open the correct workbook and specific worksheet...)

              rng = Range("U3:U" & Cells.SpecialCells(xlCellTypeLastCell).row).Value
              For x = 1 To UBound(rng, 1)
                  MsgBox"    For 'x' = " & x & "  Value at 'rng(" & x & ", 1)' is: " & rng(x, 1)      '<== this read is OK! All values are shown.
                  If rng(x, 1) = "" Then
                      rng(x, 1) = "No description provided"                                                    '<== this write doesn't appear to work...the cell still is blank ("").
                  End if
              Next x

              (following code....)

Thanks for any insight provided,
Grant

Using TRIM with Evaluate Isn't Working

$
0
0
Hi,

I'm trying to use the following code to remove any leading or trailing spaces from values
in column "C" of my worksheet:

Code:


              With Range(Cells(3, "C"), Cells(Rows.Count, "C").End(xlUp)
                  .Value = Evaluate(Trim(" & .Address & "))
              End With

Starting with initial values in column "C" of: J9768A, JC028A#A1X, JC085A, etc.,
after running the above mentioned code, I get "#VALUE!" in all of the cells in column "C".
Additionally, I tried to substitute ".Value" for ".Address" but get the same result.
Any ideas why I'm getting the "#VALUE!" result?

Thank You for any help provided.

MsOf365 Can I invoke a button via code?

$
0
0
At work we are trying to use a CRM system. Said system has a plugin for Outlook that we have installed. One of the buttons that the plugin includes lets the user upload an email to the CRM system. The catch is, it can only handle one email at a time. We have a lot of emails we want to upload from a number of different folders and we would rather not do it manually. I figure I can write code to select each email automatically, but I'm not sure if I can trigger the button/tool from the addin via code after each email is selected. Any suggestions?

Allan

How do I manipulate data in variant arrays using RtlMoveMemory with VB6/VBA

$
0
0
I have written a VB-Class to provide a data table, which is allowing you to handle data in a two-dimensional array (of type variant) similar to a ADO recordset.

To improve processing speed when adding records to the array, sorting the array (i.e. moving records around in the array) or reading records from the array, I want to use the RtlMoveMemory routine of the kernel32.dll of the Windows API. Whilst I have been able to successfully move around records within the array, writing data to a specific index of the array or reading data from a specific index of the array seems to somehow mix up the data upon further processing.

I have done quite a bit of reading to get where I am including the following:

1. http://www.codeguru.com/vb/gen/vb_mi...tores-Data.htm
2. https://stackoverflow.com/questions/...ference-in-vba
3. https://stackoverflow.com/questions/...43721#24843721

As you will see, my code is an adaption of link no. 3 above. I am not a real pro but I am not an absolute beginner neither and I must be missing something but I can't figure out what.

Here is the code as it stands today:

Code:

Option Explicit
Option Base 1

'#======================================================================================================================
'# References
'#======================================================================================================================
#If Win64 Then
    Private Const PTR_LENGTH As Long = 8
    Private Declare PtrSafe Function VarPtrArray Lib "VBE7" Alias "VarPtr" (ByRef Var() As Any) As LongPtr
    Private Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
#Else
    Private Const PTR_LENGTH As Long = 4
    Private Declare Function VarPtrArray Lib "VBE7" Alias "VarPtr" (ByRef Var() As Any) As LongPtr
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
#End If


'#======================================================================================================================
'# API Constants, Enumerations & Types
'#======================================================================================================================

'Type Declarations needed for SafeArray hacks

'The bounds of the SafeArray
Private Type SAFEARRAYBOUND
    cElements    As Long
    lLbound      As Long
End Type

Private Type SAFEARRAY1D
    cDims          As Integer
    fFeatures      As Integer
    cbElements      As Long
    cLocks          As Long
    pvData          As Long
    Bounds(0 To 0)  As SAFEARRAYBOUND
End Type

Private Type SAFEARRAY2D
    cDims          As Integer
    fFeatures      As Integer
    cbElements      As Long
    cLocks          As Long
    pvData          As Long
    Bounds(0 To 1)  As SAFEARRAYBOUND
End Type


'#======================================================================================================================
'# Private Variables
'#======================================================================================================================
Private m_List() As Variant                    ' The list array.


'#======================================================================================================================
'# Test Routines
'#======================================================================================================================

Private Sub MainTest()

    Dim iIdx As Long
    Dim aSingleRec() As Variant
    Dim i As Long

    LoadRange ActiveSheet.Range("dataInput")


    DataRowMove 5, 2

    DebugRecord 5

    DebugRecord 2


    ReDim aSingleRec(LBound(m_List, 1) To UBound(m_List, 1))

    aSingleRec(1) = "Test Gender (m)"
    aSingleRec(2) = "Steve"
    aSingleRec(3) = "Rogers"
    aSingleRec(4) = "425 Lafayette St"
    aSingleRec(5) = 10003
    aSingleRec(6) = "New York"

    DataRowPush 4, aSingleRec

    DebugRecord 4
    DebugSingleRecord aSingleRec


    aSingleRec(1) = "Test Gener (f)"
    aSingleRec(2) = "Wanda"
    aSingleRec(3) = "Maximoff"
    aSingleRec(4) = "72 W 36th St"
    aSingleRec(5) = 10018
    aSingleRec(6) = "New York"

    DataRowPush 6, aSingleRec

    DebugRecord 6
    DebugSingleRecord aSingleRec

    aSingleRec = DataRowGet(7)

    DebugSingleRecord aSingleRec

    DumpToRange ActiveSheet, ActiveSheet.Cells(10, 2)

    Debug.Print "Done..."


End Sub



Private Sub LoadRange(rInput As Range)

    m_List = rInput


End Sub


Private Sub DumpToRange(TargetWorksheet As Worksheet, TargetCell As Range)

    Dim iRow As Integer: iRow = TargetCell.Row
    Dim iCol As Integer: iCol = TargetCell.Column

    TargetWorksheet.Cells(iRow, iCol).Resize(UBound(m_List), UBound(m_List, 2)) = m_List


End Sub


Private Sub DebugRecord(iIdx As Long, Optional stInProcedure = "Main")

    Dim i As Long

    Debug.Print "---------------------------"
    Debug.Print "Record " & iIdx & " (in Procedure '" & stInProcedure & "')" & vbCrLf

    For i = 1 To UBound(m_List, 1)
        Debug.Print vbTab & "Field " & i & "[" & TypeName(m_List(i, iIdx)) & "] -> " & m_List(i, iIdx)
    Next i

    Debug.Print vbCrLf


End Sub


Private Sub DebugSingleRecord(aRec() As Variant)

    Dim i As Long

    Debug.Print "---------------------------"
    Debug.Print "Single Record " & vbCrLf

    For i = 1 To UBound(aRec)
        Debug.Print vbTab & "Field " & i & "[" & TypeName(aRec(i)) & "] -> " & aRec(i)
    Next i

    Debug.Print vbCrLf



End Sub


'#======================================================================================================================
'# Data Handling Routines
'#======================================================================================================================

Private Function DataRowGet(ByVal idxFrom As Long) As Variant()

    Dim ptrToArrayVar As LongPtr
    Dim ptrToSafeArray As LongPtr
    Dim ptrToArrayData As LongPtr
    Dim ptrToArrayData2 As LongPtr
    Dim uSAFEARRAY As SAFEARRAY1D
    Dim ptrCursor As LongPtr
    Dim cbElements As Long
    Dim atsBound1 As Long
    Dim elSize As Long

    Dim aSingleRec() As Variant

    Dim m_NumCols As Long


    m_NumCols = UBound(m_List, 1)

    ReDim aSingleRec(LBound(m_List, 1) To UBound(m_List, 1))

    'determine bound1 of source array (ie row Count)
    atsBound1 = m_NumCols

    'get pointer to source array Safearray
    ptrToArrayVar = VarPtrArray(m_List)
    CopyMemory ptrToSafeArray, ByVal ptrToArrayVar, PTR_LENGTH
    'get the safearray structure
    CopyMemory uSAFEARRAY, ByVal ptrToSafeArray, LenB(uSAFEARRAY)
    'get the pointer to the data elemets
    ptrToArrayData = uSAFEARRAY.pvData
    'determine byte size of source elements
    cbElements = uSAFEARRAY.cbElements

    'get pointer to destination array Safearray
    ptrToArrayVar = VarPtrArray(aSingleRec)
    CopyMemory ptrToSafeArray, ByVal ptrToArrayVar, PTR_LENGTH
    CopyMemory uSAFEARRAY, ByVal ptrToSafeArray, LenB(uSAFEARRAY)
    ptrToArrayData2 = uSAFEARRAY.pvData

    'determine elements size
    elSize = m_NumCols
    'determine start position of data in source array
    ptrCursor = ptrToArrayData + (((idxFrom - 1) * atsBound1) * cbElements)
    'Copy source array to destination array
    CopyMemory ByVal ptrToArrayData2, ByVal ptrCursor, cbElements * elSize


    DataRowGet = aSingleRec

    ReDim aSingleRec(0 To 0)


End Function


Private Sub DataRowPush(ByVal idxTo As Long, ByRef sourceArray() As Variant)

    Dim ptrToArrayVar As LongPtr
    Dim ptrToSafeArray As LongPtr
    Dim ptrToArrayData As LongPtr
    Dim ptrToArrayData2 As LongPtr
    Dim uSAFEARRAY As SAFEARRAY1D
    Dim ptrCursor As LongPtr
    Dim ptrCursorSource As LongPtr
    Dim cbElementsS As Long
    Dim cbElementsT As Long
    Dim atsBound1 As Long
    Dim elSize As Long
    Dim m_NumCols As Long

    Dim aSingleRec() As Variant

    aSingleRec = sourceArray

    m_NumCols = UBound(m_List, 1)

    'determine bound1 of source array (ie row Count)
    atsBound1 = m_NumCols

    'get pointer to target array Safearray
    ptrToArrayVar = VarPtrArray(m_List)
    CopyMemory ptrToSafeArray, ByVal ptrToArrayVar, PTR_LENGTH
    'get the safearray structure
    CopyMemory uSAFEARRAY, ByVal ptrToSafeArray, LenB(uSAFEARRAY)
    'get the pointer to the data elemets
    ptrToArrayData = uSAFEARRAY.pvData
    'determine byte size of source elements
    cbElementsT = uSAFEARRAY.cbElements



    'get pointer to source array Safearray
    ptrToArrayVar = VarPtrArray(aSingleRec)
    CopyMemory ptrToSafeArray, ByVal ptrToArrayVar, PTR_LENGTH
    'get the safearray structure
    CopyMemory uSAFEARRAY, ByVal ptrToSafeArray, LenB(uSAFEARRAY)
    'get the pointer to the data elemets
    ptrToArrayData2 = uSAFEARRAY.pvData
    'determine byte size of source elements
    cbElementsS = uSAFEARRAY.cbElements

    'determine elements size
    elSize = m_NumCols
    'determine start position of data in target array
    ptrCursor = ptrToArrayData + (((idxTo - 1) * atsBound1) * cbElementsT)
    'Copy source array to destination array
    CopyMemory ByVal ptrCursor, ByVal ptrToArrayData2, cbElementsS * elSize

    'Debugging only
    DebugRecord idxTo, "DataRowPush"

End Sub


Private Sub DataRowMove(ByVal idxFrom As Long, ByVal idxTo As Long)

    Dim ptrToArrayVar As LongPtr
    Dim ptrToSafeArray As LongPtr
    Dim ptrToArrayData As LongPtr
    Dim ptrToArrayData2 As LongPtr
    Dim uSAFEARRAY As SAFEARRAY1D
    Dim ptrCursorFrom As LongPtr
    Dim ptrCursorTo As LongPtr
    Dim cbElements As Long
    Dim atsBound1 As Long
    Dim elSize As Long
    Dim m_NumCols As Long

    m_NumCols = UBound(m_List, 1)

    'determine bound1 of source array (ie row Count)
    atsBound1 = m_NumCols

    'get pointer to source array Safearray
    ptrToArrayVar = VarPtrArray(m_List)
    CopyMemory ptrToSafeArray, ByVal ptrToArrayVar, PTR_LENGTH

    'get the safearray structure
    CopyMemory uSAFEARRAY, ByVal ptrToSafeArray, LenB(uSAFEARRAY)

    'get the pointer to the data elemets
    ptrToArrayData = uSAFEARRAY.pvData

    'determine byte size of source elements
    cbElements = uSAFEARRAY.cbElements

    'determine elements size
    elSize = m_NumCols

    'determine start position of  data source in array
    ptrCursorFrom = ptrToArrayData + (((idxFrom - 1) * atsBound1) * cbElements)

    'determine start position of data target in array
    ptrCursorTo = ptrToArrayData + (((idxTo - 1) * atsBound1) * cbElements)

    'Copy source array to destination array
    CopyMemory ByVal ptrCursorTo, ByVal ptrCursorFrom, cbElements * elSize

End Sub

This results in the following output:

Code:

---------------------------
Record 5 (in Procedure 'Main')

  Field 1[String] -> Mr
  Field 2[String] -> Peter
  Field 3[String] -> Parker
  Field 4[String] -> 401 7th Ave
  Field 5[Double] -> 10001
  Field 6[String] -> New York


---------------------------
Record 2 (in Procedure 'Main')

  Field 1[String] -> Mr
  Field 2[String] -> Peter
  Field 3[String] -> Parker
  Field 4[String] -> 401 7th Ave
  Field 5[Double] -> 10001
  Field 6[String] -> New York


---------------------------
Record 4 (in Procedure 'DataRowPush')

  Field 1[String] -> Test Gender (m)
  Field 2[String] -> Steve
  Field 3[String] -> Rogers
  Field 4[String] -> 425 Lafayette St
  Field 5[Integer] -> 10003
  Field 6[String] -> New York


---------------------------
Record 4 (in Procedure 'Main')

  Field 1[String] -> Test Gender (m)
  Field 2[String] -> Steve
  Field 3[String] ->  Field
  Field 4[String] ->  Field 4[String
  Field 5[Integer] -> 10003
  Field 6[String] -> New York


---------------------------
Single Record

  Field 1[String] -> Test Gender (m)
  Field 2[String] -> Steve
  Field 3[String] -> Rogers
  Field 4[String] -> 425 Lafayette St
  Field 5[Integer] -> 10003
  Field 6[String] -> New York


---------------------------
Record 6 (in Procedure 'DataRowPush')

  Field 1[String] -> Test Gener (f)
  Field 2[String] -> Wanda
  Field 3[String] -> Maximoff
  Field 4[String] -> 72 W 36th St
  Field 5[Integer] -> 10018
  Field 6[String] -> New York


---------------------------
Record 6 (in Procedure 'Main')

  Field 1[String] -> Test Gener (f)
  Field 2[String] ->  Field
  Field 3[String] -> Maximoff
  Field 4[String] -> 72 W 36th St
  Field 5[Integer] -> 10018
  Field 6[String] -> New York


---------------------------
Single Record

  Field 1[String] -> Test Gener (f)
  Field 2[String] -> Wanda
  Field 3[String] -> Maximoff
  Field 4[String] -> 72 W 36th St
  Field 5[Integer] -> 10018
  Field 6[String] -> New York


---------------------------
Single Record

  Field 1[String] -> Mr
  Field 2[String] -> Bruce
  Field 3[String] -> Banner
  Field 4[String] -> 222 W 51st St
  Field 5[Double] -> 10019
  Field 6[String] -> New York


Done...

My main issue is with 'DataRowPush' which seems to work fine while within the procedure itself but as soon as the program returns to the calling procedure, the content of the target array seems to be altered. You can see this in the debug output of records 4 and 6 above.

Similarly when reading the data with 'DataRowGet', the target single dimensional array is correctly populated but it seems the original data in m_List (the 2-dimensional array) seems to be altered as well. After reading the data with 'DataRowGet' Record no. 7 reads as

Code:

Mr
Resize
6
Field 6
10019
Field 6[

in m_List. Appreciate any help how to change my code to prevent the altering of the data.

Writing a simple macro -

$
0
0
Hi

I would like to write a few macros to help someone in my current workplace to organise their email. In particular, there are quite a few 'daily-update' emails.

I found two very helpful pages:
https://www.slipstick.com/developer/...ssage-arrives/
https://www.slipstick.com/developer/...-messages-read
https://www.slipstick.com/outlook/ru...umber-of-days/

I would use link number 3, but the archive settings are pre-set. I would be grateful for help to modify 1 or 2 as programming is not my discipline.

Code:

Sub DeleteOlderMessages(Item As Outlook.MailItem)

Dim objInbox As Outlook.MAPIFolder
Dim intCount As Integer
Dim objVariant As Variant

Set objInbox = Session.GetDefaultFolder(olFolderInbox)

' Remove these lines if you don't want to add a category
Item.Categories = "Delete Older"
Item.Save

For intCount = objInbox.Items.Count To 1 Step -1
 Set objVariant = objInbox.Items.Item(intCount)
 If objVariant.MessageClass = "IPM.Note" Then
    If objVariant.Subject = Item.Subject And objVariant.SentOn < Item.SentOn Then
    objVariant.Delete
    Else
    End If
 End If
Next

Set objInbox = Nothing
End Sub


For the third link, what would the term be to mark as read, rather than delete? As below, borrowed from link 2?

Code:

objVariant.Unread=False
Secondly, I do not know how to modify 3 to delete emails from a certain sender/same subject, which are older than 30 days, say. I'm not too sure about this one - link 1 does not help, as archiving is pre-set and cannot be altered.

Thanks,

Luke

How to fix confused Access Database after changing library object?

$
0
0
My problem started when i used to have office 2007 then started to work on my vs 2015 project then i wanted to run the spell checker from word to check textboxes on my project then I decided to download office 2016 with it's word 16.0 library object so the user won't have a future problem with old office library but then I had the problem shown in the image below after trying to run the program.


Attachment 148343

What should i do now?

Thank you

MsOf13 Intercept Picture Placeholder Event

$
0
0
Hey guys,

I have a picture placeholder on a slide and what I want to do is the following: is it possible to intercept the event when clicking on the little picture icon in the middle of the placeholder to insert a picture? I would like to set a different default folder that the placeholder reaches out to (e.g. V:/Share/Images) instead of the default C:../User/Picture folder.

Name:  2017-06-07 14_35_14-nbk10cbuching.marketmind.at - Remotedesktopverbindung.png
Views: 35
Size:  40.2 KB

Thanks a lot
Attached Images
 

(Excell) Adding +1 or time value to existing file names when saving in VB

$
0
0
HI
I am new to Visual Basic and looking at upgrading some code (colleague who entered code has retired) that we use in Excel for system outages. It is Save/Save As code.
It uses text from several cells to create a file name: Example, a number value from J3 and a Date value from I5. Then it creates a Directory from J3 and creates the file name we use.

Example J3 = 4 & I5 = 29-May-2017 then the file name is saved in Dir. 4\4_29-May-2017.xlsx
If a second outage occurs on the same day then it overwrites the file which we do not want. By adding the time value or +1 at the end we could have noumerous files created with the same name on the same day.

What we need is one of 2 things, either a way of adding a time value (as text 12:00 converted to 1200)to the file name (say P5 is 12:00) or add a running counter to the file name if it detects an existing file name that is the same as the one that if being saved. Adding the time (as text to the file name would be the preferred method but either way would work for us.
Any help from the professionals would be appreciated.

The existing code is listed below:

Sub SaveToDir2()
'
Dim wbk As Workbook
'
CDir = ActiveWorkbook.Path
'
SaveDir = CDir & "\" & ActiveSheet.Range("J3")
'
'check to see if Dir exists if not create it. Could also abort if the Dir should exist
If Len(Dir(SaveDir, vbDirectory)) = 0 Then
MkDir SaveDir
End If
'
'Checks to see if the Date cell is in date format
If IsDate(ActiveSheet.Range("I5")) Then
SaveName = ActiveSheet.Range("J3") & "_" & Application.Text(ActiveSheet.Range("I5"), "DD-MMM-YYYY") & ".xlsx"
Else
SaveName = ActiveSheet.Range("J3") & "_" & Application.Text(ActiveSheet.Range("I5"), "DD-MMM-YYYY") & ".xlsx"
End If
'
'Check to see if the file already exists
If Len(Dir(SaveDir & "\" & SaveName, vbDirectory)) > 0 Then
Resp = MsgBox("File name: " & SaveName & vbCrLf & vbCrLf & "already exists in: " & vbCrLf & vbCrLf & SaveDir & vbCrLf & vbCrLf & "Press Okay to continue, Cancel to abort", vbOKCancel)
If Resp = vbCancel Then
Exit Sub
End If
' Check to see if the file is open
For Each wbk In Workbooks
If wbk.Name = SaveName Then
Resp2 = MsgBox(SaveName & " is open. Press OK to close the file or Cancel to abort", vbOKCancel)
If Resp2 = vbOK Then
Application.DisplayAlerts = False
Workbooks(SaveName).Close
Else
Exit Sub
End If
End If
Next
End If
'
Application.DisplayAlerts = False
'
Sheets("Sheet1").Copy 'Moves Sheet1 only to a new file
ActiveWorkbook.SaveAs Filename:= _
SaveDir & "\" & SaveName, FileFormat _
:=xlOpenXMLWorkbook, CreateBackup:=False 'Saves the new file
'
ActiveWindow.Close
'
MsgBox ("File name: " & SaveName & vbCrLf & vbCrLf & "has been saved to " & vbCrLf & vbCrLf & SaveDir)
'
Application.DisplayAlerts = True

End Sub

Again Thanks if any can help, if not then I must try and learn VB to remedy the problem myself.
It will take awhile but looks like VB can be lot of fun

MsOf365 Freezes After Launching Access.Application function

$
0
0
So I have a button in outlook that saves a email, then copies the file's name, and file path to an "Access" database. It does complete the function, but what ends up happening is after the button is clicked, Outlook freezes up(including vba editor). About 30 seconds later, a windows msg box says "Microsoft access has stopped working" then it says "Microsoft access is restarting" then it launches Access. I looked into the table and the record was added properly.

I tried it while Access was opened and tried it with it closed, same resort. Whats weird is if you look at the code below, I added at the very end of the function, debug.print done, to say it finished. So after I press the button, in vba editor, it does print it out before outlook starts freezing. Any help would be appreciated

Code:

'open up an access database and insert a new record, specifically the filename and path
  Set accessApp = New Access.Application
  strSQL = "INSERT INTO tbleFiles(FileName,FilePath,FileFormat,FileType_ID) VALUES ('" & sName & "','" & sPath & "','" & ext & "','" & 1 & "');"
  Call accessApp.OpenCurrentDatabase("C:\Users\Derek\Documents\SmallProjecttest.accdb")
  accessApp.Visible = False
  accessApp.CurrentProject.Connection.Execute (strSQL)
  accessApp.Quit
  Debug.Print "Done"

Need help writing some VB code

$
0
0
Hi,

I'm looking to write some code which will:

Detect 'Heading 6' style and make the numbers restart from 1.


headings.docx

This is an example document of what I want it to become but I need it to be in a macro so it will run automatically.

Thanks

Yoda
Attached Files

[RESOLVED] (Excell) Adding +1 or time value to existing file names when saving in VB

$
0
0
HI
I am new to Visual Basic and looking at upgrading some code (colleague who entered code has retired) that we use in Excel for system outages. It is Save/Save As code.
It uses text from several cells to create a file name: Example, a number value from J3 and a Date value from I5. Then it creates a Directory from J3 and creates the file name we use.

Example J3 = 4 & I5 = 29-May-2017 then the file name is saved in Dir. 4\4_29-May-2017.xlsx
If a second outage occurs on the same day then it overwrites the file which we do not want. By adding the time value or +1 at the end we could have noumerous files created with the same name on the same day.

What we need is one of 2 things, either a way of adding a time value (as text 12:00 converted to 1200)to the file name (say P5 is 12:00) or add a running counter to the file name if it detects an existing file name that is the same as the one that if being saved. Adding the time (as text to the file name would be the preferred method but either way would work for us.
Any help from the professionals would be appreciated.

The existing code is listed below:

Sub SaveToDir2()
'
Dim wbk As Workbook
'
CDir = ActiveWorkbook.Path
'
SaveDir = CDir & "\" & ActiveSheet.Range("J3")
'
'check to see if Dir exists if not create it. Could also abort if the Dir should exist
If Len(Dir(SaveDir, vbDirectory)) = 0 Then
MkDir SaveDir
End If
'
'Checks to see if the Date cell is in date format
If IsDate(ActiveSheet.Range("I5")) Then
SaveName = ActiveSheet.Range("J3") & "_" & Application.Text(ActiveSheet.Range("I5"), "DD-MMM-YYYY") & ".xlsx"
Else
SaveName = ActiveSheet.Range("J3") & "_" & Application.Text(ActiveSheet.Range("I5"), "DD-MMM-YYYY") & ".xlsx"
End If
'
'Check to see if the file already exists
If Len(Dir(SaveDir & "\" & SaveName, vbDirectory)) > 0 Then
Resp = MsgBox("File name: " & SaveName & vbCrLf & vbCrLf & "already exists in: " & vbCrLf & vbCrLf & SaveDir & vbCrLf & vbCrLf & "Press Okay to continue, Cancel to abort", vbOKCancel)
If Resp = vbCancel Then
Exit Sub
End If
' Check to see if the file is open
For Each wbk In Workbooks
If wbk.Name = SaveName Then
Resp2 = MsgBox(SaveName & " is open. Press OK to close the file or Cancel to abort", vbOKCancel)
If Resp2 = vbOK Then
Application.DisplayAlerts = False
Workbooks(SaveName).Close
Else
Exit Sub
End If
End If
Next
End If
'
Application.DisplayAlerts = False
'
Sheets("Sheet1").Copy 'Moves Sheet1 only to a new file
ActiveWorkbook.SaveAs Filename:= _
SaveDir & "\" & SaveName, FileFormat _
:=xlOpenXMLWorkbook, CreateBackup:=False 'Saves the new file
'
ActiveWindow.Close
'
MsgBox ("File name: " & SaveName & vbCrLf & vbCrLf & "has been saved to " & vbCrLf & vbCrLf & SaveDir)
'
Application.DisplayAlerts = True

End Sub

Again Thanks if any can help, if not then I must try and learn VB to remedy the problem myself.
It will take awhile but looks like VB can be lot of fun

Opening Internet explorer multiple sessions with VBA

$
0
0
Hello everybody!
I'm new in this forum and i would like to know if somebody could help me.
I'm writing a Macro in VBA to interact with Internet explorer to open multiple sessions in internet explorer and log in into a site.
The problem is that when i use the createobject function i will be able to interact with every page opened but they are opened in the same session. Basically it opens 2 different windows not sessions in IE.

CreateObject("InternetExplorer.Application")

To try to solve the problem i tried to use the shell function to open IE in multiple sessions and i can.

Shell "C:\Program Files\Internet Explorer\iexplore.exe", -noframemerging

The problem here is that i don't know how to interact with IE. In witch way can get that IE new session as object?

I think that is really strange there is no option in the creation object function to open a news session.

Anybody can help?

Thanks
Viewing all 4673 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>