Hi all,
I have wrote some code which calls a query using querydefs and then pulls all the records into a table. This table is then exported to excel, however I seem to be having some trouble with the export and am finding it difficult to identify where the problem is coming from. When I run my code in step by step, more of than not the code passes fine and exports to excel. However, most of the time when I run the code as a whole without step by step, then the excel application will load but the workbook will not. The application then continues to close and the code completes without error? The code for the opening of the excel file is below.
The pause is a function i created to see if it was a problem of giving the exel application some time to load!
I should also add then when the matrix does export there are no problems at all!
I have wrote some code which calls a query using querydefs and then pulls all the records into a table. This table is then exported to excel, however I seem to be having some trouble with the export and am finding it difficult to identify where the problem is coming from. When I run my code in step by step, more of than not the code passes fine and exports to excel. However, most of the time when I run the code as a whole without step by step, then the excel application will load but the workbook will not. The application then continues to close and the code completes without error? The code for the opening of the excel file is below.
The pause is a function i created to see if it was a problem of giving the exel application some time to load!
Code:
Sub MiseEnForme1_Excel()
Dim AppExcel As Excel.Application
Dim WkbExcel As Excel.Workbook
Dim WksExcel As Excel.Worksheet
Set AppExcel = New Excel.Application
AppExcel.Visible = True
Pause (5)
Set WkbExcel = Workbooks.Add
WkbExcel.Activate
Pause (5)
Sheets("Feuil1").Name = "DailyFees"
Sheets("DailyFees").Activate
Range("A1").Select
With Selection.Font
.Name = "Arial"
.Size = 14
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Range("1:1").Select
Selection.RowHeight = 50
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 8282112
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("4:4").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 8282112
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("A4").Select
ActiveCell.FormulaR1C1 = "Deal Id"
Range("B4").Select
ActiveCell.FormulaR1C1 = "Brokerage Firm"
Range("C4").Select
ActiveCell.FormulaR1C1 = "Client Company"
Range("D4").Select
ActiveCell.FormulaR1C1 = "Product Purchased"
Range("E4").Select
ActiveCell.FormulaR1C1 = "Shares Purchased"
Range("F4").Select
ActiveCell.FormulaR1C1 = "Management Fee %"
Range("G4").Select
ActiveCell.FormulaR1C1 = "Retro Fees %"
Range("H4").Select
ActiveCell.FormulaR1C1 = "Date de Valorisation"
Range("I4").Select
ActiveCell.FormulaR1C1 = "Valeur Liquidative"
Range("J4").Select
ActiveCell.FormulaR1C1 = "Days at VL"
Range("L4").Select
ActiveCell.FormulaR1C1 = "Daily Fees"
Range("A4:Z4").Select
Selection.RowHeight = 20
With Selection.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
End Sub
I should also add then when the matrix does export there are no problems at all!
Last edited: